dbctlgo

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DatabasePostgres is a postgres database
	DatabasePostgres = "postgres"
	// DatabaseRedis is a redis database
	DatabaseRedis = "redis"
)

Database types

Variables

View Source
var (
	// ErrInvalidDatabaseType is returned when an invalid database type is passed
	ErrInvalidDatabaseType = errors.New("invalid database type")
)

Functions

func CreateDB

func CreateDB(dbType string, opts ...Option) (string, error)

CreateDB create a database and return connection string it up to the caller to remove the database by calling RemoveDB

func MustCreateDB

func MustCreateDB(t *testing.T, dbType string, opts ...Option) string

MustCreateDB create a database and return connection string or fail the test it will also remove the database after the test is finished

func MustCreatePostgresDB

func MustCreatePostgresDB(t *testing.T, opts ...Option) string

MustCreatePostgresDB create a postgres database and return connection string or fail the test

func MustCreateRedisDB

func MustCreateRedisDB(t *testing.T, opts ...Option) string

MustCreateRedisDB create a redis database and return connection string or fail the test

func RemoveDB

func RemoveDB(dbType, uri string) error

RemoveDB remove a database using connection string

Types

type CreateDBRequest

type CreateDBRequest struct {
	Type       string `json:"type"`
	Migrations string `json:"migrations"`
	Fixtures   string `json:"fixtures"`

	// postgres instance information
	InstancePort uint32 `json:"instance_port"`
	InstanceUser string `json:"instance_user"`
	InstancePass string `json:"instance_pass"`
	InstanceName string `json:"instance_name"`
}

CreateDBRequest is the request object for creating a database

type CreateDBResponse

type CreateDBResponse struct {
	URI string `json:"uri"`
}

CreateDBResponse is the response object for creating a database

type ErrorMessage

type ErrorMessage struct {
	Error string `json:"error"`
}

ErrorMessage is representing rest api error object

type Option

type Option func(*config) error

Option is a function that configures the client.

func WithDefaultMigrations

func WithDefaultMigrations() Option

WithDefaultMigrations configures the client to use the default migrations.

func WithFixtures

func WithFixtures(fixtures string) Option

WithFixtures configures the client to use the given fixtures.

func WithHost

func WithHost(address string, port uint32) Option

WithHost configures the client to use the given host.

func WithInstance

func WithInstance(user, pass, address, dbname string, port uint32) Option

WithInstance configures the client to use the given postgres instance.

func WithMigrations

func WithMigrations(migrations string) Option

WithMigrations configures the client to use the given migrations.

type RemoveDBRequest

type RemoveDBRequest struct {
	Type string `json:"type"`
	URI  string `json:"uri"`
}

RemoveDBRequest is the request object for removing a database

type Request

type Request interface {
	CreateDBRequest | RemoveDBRequest
}

Request is eatheir CreateDBRequest or RemoveDBRequest

type Response

type Response interface {
	CreateDBResponse | interface{}
}

Response is eatheir CreateDBResponse or ErrorMessage

Jump to

Keyboard shortcuts

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