dolt

package module
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 8 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

func WithCredsFile

func WithCredsFile(credsFile string) testcontainers.CustomizeRequestOption

func WithDatabase

func WithDatabase(database string) testcontainers.CustomizeRequestOption

func WithDefaultCredentials deprecated

func WithDefaultCredentials() testcontainers.CustomizeRequestOption

Deprecated: this function will be removed in the next major release.

func WithDoltCloneRemoteUrl

func WithDoltCloneRemoteUrl(url string) testcontainers.CustomizeRequestOption

func WithDoltCredsPublicKey

func WithDoltCredsPublicKey(key string) testcontainers.CustomizeRequestOption

func WithPassword

func WithPassword(password string) testcontainers.CustomizeRequestOption

func WithScripts

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

func WithUsername

func WithUsername(username string) testcontainers.CustomizeRequestOption

Types

type DoltContainer

type DoltContainer struct {
	testcontainers.Container
	// contains filtered or unexported fields
}

DoltContainer represents the Dolt container type used in the module

func Run added in v0.32.0

Run creates an instance of the Dolt container type

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

doltContainer, err := dolt.Run(ctx,
	"dolthub/dolt-sql-server:1.32.4",
	dolt.WithConfigFile(filepath.Join("testdata", "dolt_1_32_4.cnf")),
	dolt.WithDatabase("foo"),
	dolt.WithUsername("root"),
	dolt.WithPassword("password"),
	dolt.WithScripts(filepath.Join("testdata", "schema.sql")),
)
defer func() {
	if err := testcontainers.TerminateContainer(doltContainer); err != nil {
		log.Printf("failed to terminate container: %s", err)
	}
}()
if err != nil {
	log.Printf("failed to run dolt container: %s", err)
	return
}
// }

state, err := doltContainer.State(ctx)
if err != nil {
	log.Printf("failed to get container state: %s", err)
	return
}

fmt.Println(state.Running)
Output:

true
Example (Connect)
ctx := context.Background()

doltContainer, err := dolt.Run(ctx,
	"dolthub/dolt-sql-server:1.32.4",
	dolt.WithConfigFile(filepath.Join("testdata", "dolt_1_32_4.cnf")),
	dolt.WithDatabase("foo"),
	dolt.WithUsername("bar"),
	dolt.WithPassword("password"),
	dolt.WithScripts(filepath.Join("testdata", "schema.sql")),
)
defer func() {
	if err := testcontainers.TerminateContainer(doltContainer); err != nil {
		log.Printf("failed to terminate container: %s", err)
	}
}()
if err != nil {
	log.Printf("failed to run dolt container: %s", err)
	return
}

connectionString := doltContainer.MustConnectionString(ctx)

db, err := sql.Open("mysql", connectionString)
if err != nil {
	log.Printf("failed to open database connection: %s", err)
	return
}
defer db.Close()

if err = db.Ping(); err != nil {
	log.Printf("failed to ping database: %s", err)
	return
}
stmt, err := db.Prepare("SELECT dolt_version();")
if err != nil {
	log.Printf("failed to prepare sql statement: %s", err)
	return
}
defer stmt.Close()
row := stmt.QueryRow()
version := ""
err = row.Scan(&version)
if err != nil {
	log.Printf("failed to scan row: %s", err)
	return
}

fmt.Println(version)
Output:

1.32.4

func RunContainer deprecated

Deprecated: use Run instead RunContainer creates an instance of the Couchbase container type

func (*DoltContainer) ConnectionString

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

func (*DoltContainer) MustConnectionString

func (c *DoltContainer) MustConnectionString(ctx context.Context, args ...string) string

Jump to

Keyboard shortcuts

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