Documentation ¶
Index ¶
- func Connect(ctx context.Context, databaseURL string) (*sql.DB, error)
- func ConnectionString(host string, port uint16, name, sslMode, user, pass string) string
- func CreateDatabaseIfNotExists(ctx context.Context, databaseURL string) (bool, error)
- func DatabaseExists(ctx context.Context, databaseURL string) (bool, error)
- func DropDatabaseIfExists(ctx context.Context, databaseURL string) (bool, error)
- func IsDBNotExists(err error) bool
- func IsDup(err error) bool
- func IsDupDB(err error) bool
- func IsDupUser(err error) bool
- func IsForeignKeyViolation(err error) bool
- func IsNotFound(err error) bool
- func IsPSQLError(err error, code string) bool
- func IsPerm(err error) bool
- func WithDatabaseName(databaseName string) startConfigFunc
- func WithInMemory(inMemory bool) startConfigFunc
- func WithIsTemplate(isTemplate bool) startConfigFunc
- func WithPostStart(funcs ...postStartFunc) startConfigFunc
- func WithTimeout(timeout time.Duration) startConfigFunc
- type Container
- type ContainerCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConnectionString ¶
ConnectionString builds the connection string from the individual components.
func CreateDatabaseIfNotExists ¶
CreateDatabaseIfNotExists creates a PostgrSQL database if it doesn't already exist.
func DatabaseExists ¶
DatabaseExists checks if the given database on a PostgreSQL server does exist.
func DropDatabaseIfExists ¶
DropDatabaseIfExists drops a PostgrSQL database if it exist.
func IsDBNotExists ¶
IsDBNotExists returns true if the given error indicates error code 3D000: database "..." does not exist.
func IsDup ¶
IsDup returns true if the given error indicates that a duplicate record has been found (23505 unique_violation).
func IsDupDB ¶
IsDupDB returns true if the given error indicates the database already exists. This is typically returned from the `CREATE DATABASE dbname` command if `dbname` already exists (42P04 database "..." already exists).
func IsDupUser ¶
IsDupUser returns true if the given error indicates the user/role already exists. This is typically returned from the `CREATE ROLE user ...` command if `user` already exists (42710 role "..." already exists).
func IsForeignKeyViolation ¶
IsForeignKeyViolation returns true if the given error indicates a violation of a foreign key constraint (23503 foreign_key_violation).
func IsNotFound ¶
IsNotFound returns true if the given error indicates that a record could not be found.
func IsPSQLError ¶
IsPSQLError returns true if the given error is from PostgreSQL and has the given error code.
See https://www.postgresql.org/docs/13/errcodes-appendix.html for a list of all PostgreSQL error codes.
func IsPerm ¶
IsPerm returns true if the given error indicates a permission issue (42501 insufficient_privilege).
func WithDatabaseName ¶
func WithDatabaseName(databaseName string) startConfigFunc
func WithInMemory ¶
func WithInMemory(inMemory bool) startConfigFunc
func WithIsTemplate ¶
func WithIsTemplate(isTemplate bool) startConfigFunc
func WithPostStart ¶
func WithPostStart(funcs ...postStartFunc) startConfigFunc
WithPostStart adds a post-startup operation to the container. This can be used to install extensions, create tables, seed data etc.
func WithTimeout ¶
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
func (*Container) ConnConfig ¶
func (c *Container) ConnConfig() *pgx.ConnConfig
type ContainerCache ¶
type ContainerCache struct {
// contains filtered or unexported fields
}
ContainerCache is a thread-safe cache for Postgres containers.
func NewContainerCache ¶
func NewContainerCache() *ContainerCache
NewContainerCache returns a new ContainerCache.
func (*ContainerCache) Close ¶
func (p *ContainerCache) Close() error
Close stops all containers in the cache.
func (*ContainerCache) GetOrCreate ¶
func (p *ContainerCache) GetOrCreate(id string, createFunc func() *Container) *Container
GetOrCreate starts a new container if none is running, otherwise returns the pooled container.