Documentation ¶
Overview ¶
Package dockerdb allows user to create virtual databases using docker. Tested with PostgreSQL, MySQL, MS SQL.
Index ¶
- Variables
- func Pull(ctx context.Context, image DockerHubName) error
- func Run(ctx context.Context, ID string) error
- func SetMaxActualPortTries(n int)
- func SetMaxWaitTime(sec time.Duration)
- func With(ctx context.Context, c Config, fn func(c Config, vdb *VDB) error) (err error)
- func WithKeyDB(ctx context.Context, name string, checkWakeUp func(c Config) (stop bool), ...) (err error)
- func WithMySQL(ctx context.Context, name string, fn func(c Config, vdb *VDB) error) (err error)
- func WithPostgres(ctx context.Context, name string, fn func(c Config, vdb *VDB) error) (err error)
- func WithRedis(ctx context.Context, name string, checkWakeUp func(c Config) (stop bool), ...) (err error)
- func WithScyllaDB(ctx context.Context, name string, checkWakeUp func(c Config) (stop bool), ...) (err error)
- type Config
- func EmptyConfig() *Config
- func KeyDBConfig(dbname string, closure func(c Config) (stop bool)) *Config
- func MySQLConfig(dbname string) *Config
- func PostgresConfig(dbname string) *Config
- func RedisConfig(dbname string, closure func(c Config) (stop bool)) *Config
- func ScyllaDBConfig(dbname string, closure func(c Config) (stop bool)) *Config
- func (c *Config) ActualPort(port nat.Port) *Config
- func (c *Config) Build() Config
- func (c *Config) Cmd(cmd []string) *Config
- func (c *Config) DBName(name string) *Config
- func (c *Config) DBPassword(password string) *Config
- func (c *Config) DBUser(user string) *Config
- func (c *Config) DockerEnv(env []string) *Config
- func (c *Config) GetActualPort() nat.Port
- func (c *Config) GetDBName() string
- func (c *Config) GetDBPassword() string
- func (c *Config) GetDBUser() string
- func (c *Config) GetEnvDocker() []string
- func (c *Config) GetSQLConnStr() string
- func (c *Config) GetStandardDBPort() nat.Port
- func (c *Config) LimitResources(resources *container.Resources) *Config
- func (c *Config) NoSQL(checkWakeUp func(conf Config) (stop bool), tries int, sleepTime time.Duration) *Config
- func (c *Config) PullImage() *Config
- func (c *Config) SQL() *Config
- func (c *Config) SetPullImage(pull bool) *Config
- func (c *Config) StandardDBPort(port nat.Port) *Config
- func (c *Config) UnimplementedSQL(connStringFormat string) *Config
- func (c *Config) Vendor(vendor DockerHubName) *Config
- type DockerHubName
- type VDB
- func (ddb *VDB) Clear(ctx context.Context) (err error)
- func (ddb *VDB) GetPort() (port nat.Port)
- func (ddb *VDB) GetSQLConnStr() string
- func (ddb *VDB) Kill(ctx context.Context, signal string) (err error)
- func (ddb *VDB) Pause(ctx context.Context) (err error)
- func (ddb *VDB) Remove(ctx context.Context) (err error)
- func (ddb *VDB) Restart(ctx context.Context) (err error)
- func (ddb *VDB) Run(ctx context.Context) (err error)
- func (ddb *VDB) SQL() (db *sql.DB)
- func (ddb *VDB) Stop(ctx context.Context) (err error)
- func (ddb *VDB) Unpause(ctx context.Context) (err error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknown = errors.New("unknown error") ErrWarning = errors.New("warning") )
Functions ¶
func Pull ¶
func Pull(ctx context.Context, image DockerHubName) error
Pull pulls an image from net. WARNING!! USE IT CAREFULLY! DOWNLOADING SOME db IMAGES MAY TAKE SOME TIME. Tested with PostgreSQL, MySQL, MS SQL.
func SetMaxActualPortTries ¶ added in v3.2.4
func SetMaxActualPortTries(n int)
func SetMaxWaitTime ¶
func WithPostgres ¶ added in v3.1.0
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func EmptyConfig ¶
func EmptyConfig() *Config
func KeyDBConfig ¶ added in v3.1.0
func MySQLConfig ¶ added in v3.1.0
func PostgresConfig ¶ added in v3.1.0
func RedisConfig ¶ added in v3.1.0
func ScyllaDBConfig ¶ added in v3.1.0
func (*Config) ActualPort ¶
ActualPort allows you to set the actual port for the database. Random unused port is used by default.
func (*Config) Build ¶
Build builds the config. After building, the config can be used and can't be changed.
func (*Config) DBPassword ¶
DBPassword sets the password of the database.
func (*Config) GetActualPort ¶
func (*Config) GetDBPassword ¶
func (*Config) GetEnvDocker ¶
func (*Config) GetSQLConnStr ¶
func (*Config) GetStandardDBPort ¶
func (*Config) LimitResources ¶ added in v3.3.0
LimitResources limits the resources of the container.
func (*Config) NoSQL ¶
func (c *Config) NoSQL(checkWakeUp func(conf Config) (stop bool), tries int, sleepTime time.Duration) *Config
NoSQL sets db kind to NoSQL.
func (*Config) SetPullImage ¶ added in v3.4.1
func (*Config) StandardDBPort ¶
StandardDBPort represents the standard port of the database which can be used to connect to it.
func (*Config) UnimplementedSQL ¶ added in v3.1.0
UnimplementedSQL sets the SQL connection string format. Example template: "{user}:{password}@127.0.0.1:{port}/{dbname}"
func (*Config) Vendor ¶
func (c *Config) Vendor(vendor DockerHubName) *Config
Vendor sets the vendor of the database.
type DockerHubName ¶
type DockerHubName string
const ( Postgres15 DockerHubName = "postgres:15" Postgres14 DockerHubName = "postgres:14" Postgres13 DockerHubName = "postgres:13" Postgres12 DockerHubName = "postgres:12" Postgres11 DockerHubName = "postgres:11" MySQL5Image DockerHubName = "mysql:5.7" MySQL8Image DockerHubName = "mysql:8" KeyDBImage DockerHubName = "eqalpha/keydb" RedisImage DockerHubName = "redis" ScyllaDBImage DockerHubName = "scylladb/scylla" )
type VDB ¶
type VDB struct {
// contains filtered or unexported fields
}
func (*VDB) GetSQLConnStr ¶ added in v3.1.2
func (*VDB) Run ¶
Run launches the docker container. Can return ErrWarning that must be not necessary to handle