Documentation
¶
Overview ¶
Package dockerdb allows user to create virtual databases using docker. Tested with PostgreSQL, MySQL, MS SQL.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/egorgasay/dockerdb"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
)
func main() {
config := dockerdb.CustomDB{
DB: dockerdb.DB{
Name: "admin",
User: "admin",
Password: "admin",
},
Port: "45217",
Vendor: dockerdb.Postgres15,
}
// This will allow you to upload the image to your computer.
ctx := context.TODO()
err := dockerdb.Pull(ctx, dockerdb.Postgres15)
if err != nil {
log.Fatal(err)
}
vdb, err := dockerdb.New(ctx, config)
if err != nil {
log.Fatal(err)
}
var answer string
err = vdb.DB.QueryRow("SELECT 'db is up'").Scan(&answer)
if err != nil {
log.Fatal(err)
}
fmt.Println(answer)
if err = vdb.Stop(ctx); err != nil {
log.Fatal(err)
}
fmt.Println("db is down")
}
Index ¶
- Constants
- Variables
- func Build(conf CustomDB) (connStr string, err error)
- func Pull(ctx context.Context, image string) error
- func Run(ctx context.Context, ID string) error
- func SetMaxWaitTime(sec time.Duration)
- type CustomDB
- type DB
- type VDB
- func (ddb *VDB) Kill(ctx context.Context, signal string) (err error)
- func (ddb *VDB) Pause(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) Stop(ctx context.Context) (err error)
- func (ddb *VDB) Unpause(ctx context.Context) (err error)
Examples ¶
Constants ¶
View Source
const ( Postgres15 = "postgres:15" Postgres14 = "postgres:14" Postgres13 = "postgres:13" Postgres12 = "postgres:12" Postgres11 = "postgres:11" MySQL5Image = "mysql:5.7" MySQL8Image = "mysql:8" )
Variables ¶
View Source
var ( ErrUnknown = errors.New("unknown error") ErrUnsupported = errors.New("unsupported db vendor") )
Functions ¶
func Pull ¶ added in v1.0.0
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 SetMaxWaitTime ¶ added in v1.2.0
Types ¶
type VDB ¶
type VDB struct {
ID string
DB *sql.DB
ConnString string
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.
