clickhouse

package module
v0.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithConfigFile

func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption

WithConfigFile sets the XML config file to be used for the clickhouse container It will also set the "configFile" parameter to the path of the config file as a command line argument to the container.

func WithDatabase

func WithDatabase(dbName string) testcontainers.CustomizeRequestOption

WithDatabase sets the initial database to be created when the container starts It can be used to define a different name for the default database that is created when the image is first started. If it is not specified, then the default value("clickhouse") will be used.

func WithInitScripts

func WithInitScripts(scripts ...string) testcontainers.CustomizeRequestOption

WithInitScripts sets the init scripts to be run when the container starts

func WithPassword

func WithPassword(password string) testcontainers.CustomizeRequestOption

WithPassword sets the initial password of the user to be created when the container starts It is required for you to use the ClickHouse image. It must not be empty or undefined. This environment variable sets the password for ClickHouse.

func WithUsername

func WithUsername(user string) testcontainers.CustomizeRequestOption

WithUsername sets the initial username to be created when the container starts It is used in conjunction with WithPassword to set a user and its password. It will create the specified user with superuser power. If it is not specified, then the default user of clickhouse will be used.

func WithYamlConfigFile

func WithYamlConfigFile(configFile string) testcontainers.CustomizeRequestOption

WithConfigFile sets the YAML config file to be used for the clickhouse container It will also set the "configFile" parameter to the path of the config file as a command line argument to the container.

func WithZookeeper added in v0.28.0

func WithZookeeper(host, port string) testcontainers.CustomizeRequestOption

WithZookeeper pass a config to connect clickhouse with zookeeper and make clickhouse as cluster

Types

type ClickHouseContainer

type ClickHouseContainer struct {
	testcontainers.Container
	DbName   string
	User     string
	Password string
}

ClickHouseContainer represents the ClickHouse container type used in the module

func RunContainer

func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ClickHouseContainer, error)

RunContainer creates an instance of the ClickHouse container type

Example
// runClickHouseContainer {
ctx := context.Background()

user := "clickhouse"
password := "password"
dbname := "testdb"

clickHouseContainer, err := clickhouse.RunContainer(ctx,
	testcontainers.WithImage("clickhouse/clickhouse-server:23.3.8.21-alpine"),
	clickhouse.WithUsername(user),
	clickhouse.WithPassword(password),
	clickhouse.WithDatabase(dbname),
	clickhouse.WithInitScripts(filepath.Join("testdata", "init-db.sh")),
	clickhouse.WithConfigFile(filepath.Join("testdata", "config.xml")),
)
if err != nil {
	log.Fatalf("failed to start container: %s", err)
}
defer func() {
	if err := clickHouseContainer.Terminate(ctx); err != nil {
		log.Fatalf("failed to terminate container: %s", err)
	}
}()
// }

state, err := clickHouseContainer.State(ctx)
if err != nil {
	log.Fatalf("failed to get container state: %s", err) // nolint:gocritic
}

fmt.Println(state.Running)

connectionString, err := clickHouseContainer.ConnectionString(ctx)
if err != nil {
	log.Fatalf("failed to get connection string: %s", err)
}

opts, err := ch.ParseDSN(connectionString)
if err != nil {
	log.Fatalf("failed to parse DSN: %s", err)
}

fmt.Println(strings.HasPrefix(opts.ClientInfo.String(), "clickhouse-go/"))
Output:

true
true

func (*ClickHouseContainer) ConnectionHost

func (c *ClickHouseContainer) ConnectionHost(ctx context.Context) (string, error)

ConnectionHost returns the host and port of the clickhouse container, using the default, native 9000 port, and obtaining the host and exposed port from the container

func (*ClickHouseContainer) ConnectionString

func (c *ClickHouseContainer) ConnectionString(ctx context.Context, args ...string) (string, error)

ConnectionString returns the dsn string for the clickhouse container, using the default, native 9000 port, and obtaining the host and exposed port from the container. It also accepts a variadic list of extra arguments which will be appended to the dsn string. The format of the extra arguments is the same as the connection string format, e.g. "dial_timeout=300ms" or "skip_verify=false"

type ZookeeperOptions added in v0.28.0

type ZookeeperOptions struct {
	Host, Port string
}

ZookeeperOptions arguments for zookeeper in clickhouse

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL