Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB interface {
QueryRow(ctx context.Context, query string, args ...any) Row
Query(ctx context.Context, query string, args ...any) (Rows, error)
Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
Close() error
}
DB is an interface for database operations
type DBOption ¶
type DBOption func(*dbOptions)
DBOption is a functional option for configuring NewDB
func WithHealthCheckPeriod ¶
WithHealthCheckPeriod sets how frequently to check the health of idle connections
func WithMaxConnIdleTime ¶
WithMaxConnIdleTime sets the maximum amount of time a connection may be idle
func WithMaxConnLifetime ¶
WithMaxConnLifetime sets the maximum amount of time a connection may be reused
func WithMaxConns ¶
WithMaxConns sets the maximum number of connections in the pool
func WithMinConns ¶
WithMinConns sets the minimum number of connections in the pool
func WithPoolContext ¶
WithPoolContext sets the context used for creating the connection pool
type FakeDB ¶
type FakeDB struct {
QueryRowFake func(ctx context.Context, query string, args ...any) Row
QueryFake func(ctx context.Context, query string, args ...any) (Rows, error)
ExecFake func(ctx context.Context, query string, args ...any) (sql.Result, error)
CloseFake func() error
}
type FakeMigrator ¶
type FakeMigrator struct {
RunMigrationsFake func(db DB, dirPath string) error
RunMigrationsToVersionFake func(db DB, dirPath string, toVersion int) error
ListMigrationsFake func(db DB, dirPath string) ([]Migration, error)
}
func (*FakeMigrator) ListMigrations ¶ added in v0.12.0
func (f *FakeMigrator) ListMigrations(db DB, dirPath string) ([]Migration, error)
func (*FakeMigrator) RunMigrations ¶
func (f *FakeMigrator) RunMigrations(db DB, dirPath string) error
func (*FakeMigrator) RunMigrationsToVersion ¶ added in v0.11.0
func (f *FakeMigrator) RunMigrationsToVersion(db DB, dirPath string, toVersion int) error
type FakeRows ¶
type Migration ¶ added in v0.11.0
type Migration struct {
Version int
Description string
Filename string
Applied bool
AppliedAt *time.Time
}
Migration represents a database migration file
func ListMigrationsFromDir ¶ added in v0.12.0
ListMigrationsFromDir returns a list of migrations from a directory without checking applied status
type Migrator ¶
type Migrator interface {
RunMigrations(db DB, dirPath string) error
RunMigrationsToVersion(db DB, dirPath string, toVersion int) error
ListMigrations(db DB, dirPath string) ([]Migration, error)
}
Migrator is an interface for running database migrations