Documentation ¶
Overview ¶
Package database implements PostgreSQL database client helpers.
Index ¶
- Constants
- Variables
- func Migrate(db *sql.DB, migrations fs.FS, direction MigrationDirection) (int, error)
- func MigrateMax(db *sql.DB, migrations fs.FS, direction MigrationDirection, maxAmount int) (int, error)
- func NewStdlib(ctx context.Context, cfg Config) (*sql.DB, error)
- type CommandTag
- type Config
- type Connection
- type Logger
- type LoggerContract
- type MigrationDirection
- type Pool
- type Querier
- type Row
- type Rows
Constants ¶
const ( // UpMigration executes migrations that are new and have not been applied yet. UpMigration = migrate.Up // DownMigration migrates down. DownMigration = migrate.Down )
Variables ¶
var ( // ErrNoRows occurs when rows are expected but none are returned. ErrNoRows = pgx.ErrNoRows // ErrRowAlreadyExists occurs when a row already exists when trying to insert. ErrRowAlreadyExists = errors.New("row already exists") // ErrTooManyRows occurs when more rows than expected are returned. ErrTooManyRows = pgx.ErrTooManyRows )
Functions ¶
func MigrateMax ¶
func MigrateMax(db *sql.DB, migrations fs.FS, direction MigrationDirection, maxAmount int) (int, error)
MigrateMax migrates the given database with the embedded migrations and direction, will apply at most `max` migrations, pass 0 for no limit.
Types ¶
type CommandTag ¶
type CommandTag = pgconn.CommandTag
CommandTag is the status text returned by PostgreSQL for a query.
type Config ¶
type Config struct { Host string `env:"HOST"` Port string `env:"PORT"` User string `env:"USER"` Password string `env:"PASSWORD"` Database string `env:"DATABASE"` Driver string `env:"DRIVER"` Logger LoggerContract }
Config contains the database configuration.
type Connection ¶
Connection defines a database connection. It exposes the exported functions of both embedded types. The connection is not concurrency-safe.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger implements a database logger.
type LoggerContract ¶
type LoggerContract interface { Log(ctx context.Context, level tracelog.LogLevel, msg string, data map[string]any) Level() tracelog.LogLevel }
LoggerContract defines the logger interface used by the database implementation.
type MigrationDirection ¶
type MigrationDirection = migrate.MigrationDirection
MigrationDirection defines the direction of the migration.
type Pool ¶
Pool defines a connection pool. It exposes the exported functions of both embedded types. The pool is concurrency-safe.