database

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyTime

func AnyTime() sqlmock.Argument

AnyTime will return an sqlmock.Argument which can match any time.Time argument.

func CreateGormDB

func CreateGormDB(logger hclog.Logger, c *config.Config) (*gorm.DB, error)

CreateGormDB creates a configured gorm.DB

func Migrate

func Migrate(databaseURL string) error

Migrate leverages golang-migrate to perform a database migration using SQL migration files embedded within the binary.

func MockQueueJob

func MockQueueJob(mock sqlmock.Sqlmock, params interface{}, job string, priority int)

func NewGormDB

func NewGormDB(databaseURL string) (*gorm.DB, error)

NewGormDB creates a gorm.DB given a database URL.

This is a utility function only to be used for tests.

func NewMockedGormDB

func NewMockedGormDB() (*gorm.DB, sqlmock.Sqlmock)

NewMockedGormDB returns a mocked gorm.DB for use in tests.

func NewTestPostgresDB

func NewTestPostgresDB(migrate bool) (*dockertest.Resource, string, error)

NewTestPostgresDB spawns a new Docker container running PostgreSQL v14.5 and executes database migration optionally.

Use "defer resource.Close()" to ensure the container is purged when you are done with it.

func Ping

func Ping(ctx context.Context, db *gorm.DB) error

Ping pings the database to test the connection

Types

type NoOpCrypter

type NoOpCrypter struct{}

NoOpCrypter is a no-op crypter useful for testing.

func (NoOpCrypter) Decrypt

func (c NoOpCrypter) Decrypt(w io.Writer, r io.Reader) error

func (NoOpCrypter) Encrypt

func (c NoOpCrypter) Encrypt(w io.Writer, r io.Reader) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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