Documentation ¶
Index ¶
- Variables
- func BeginTx(ctx context.Context, opts *sql.TxOptions) (tx *sql.Tx, err error)
- func Check(err error) error
- func Close() (err error)
- func Connect(conf config.DatabaseConfig) (err error)
- func InitializeSchema() (err error)
- func Mock() sqlmock.Sqlmock
- func Prep(query string, args ...any) (string, []any)
- type Migration
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotConnected = errors.New("not connected to the database") ErrReadOnly = errors.New("connected in readonly mode - only readonly transactions allowed") ErrNotfound = errors.New("record not found or no rows returned") )
var ( ErrNotFound = errors.New("object not found in database") ErrAlreadyExists = errors.New("object already exists in database") )
Functions ¶
func Connect ¶
func Connect(conf config.DatabaseConfig) (err error)
Connect to the Postgres database specified by the DSN. Connecting in read-only mode is managed by the package, not by the database. Multiple or concurrent calls to Connect will be ignored even if a different configuration is passed.
func InitializeSchema ¶
func InitializeSchema() (err error)
Initialize schema applies any unapplied migrations to the database and should be run when the database is first connected to. If empty is true then the migration table is created and all migrations are applied. If it is not true then the current migration of the database is fetched and all unapplied migrations are applied.
Types ¶
type Migration ¶
type Migration struct { ID int // The unique sequence ID of the migration Name string // The human readable name of the migration Version string // The package version when the migration was applied Created time.Time // The timestamp when the migration was applied Path string // The path of the migration in the filesystem }
Migration is used to represent both a SQL migration from the embedded file system and a migration record in the database. These records are compared to ensure the database is as up to date as possible before the application starts.
func Migrations ¶
Migrations returns the migration files from the embedded file system.