Documentation ¶
Index ¶
- Variables
- func EndTx(tx Tx, err error) error
- type AtomicStore
- type Beginner
- type Committer
- type Database
- type Execer
- type MigrationFormat
- func (x MigrationFormat) IsValid() bool
- func (x MigrationFormat) MarshalText() ([]byte, error)
- func (x *MigrationFormat) Scan(value interface{}) (err error)
- func (x MigrationFormat) String() string
- func (x *MigrationFormat) UnmarshalText(text []byte) error
- func (x MigrationFormat) Value() (driver.Value, error)
- type Migrator
- type MigratorConfig
- type NewStoreFunc
- type Querier
- type Rollbacker
- type TableOperator
- type Transactor
- type Tx
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidMigrationFormat = errors.New("not a valid MigrationFormat")
Functions ¶
Types ¶
type AtomicStore ¶
type AtomicStore[T any] struct { // contains filtered or unexported fields }
func NewAtomicStore ¶
func NewAtomicStore[T any](db Database, newStoreFunc NewStoreFunc[T]) *AtomicStore[T]
NewAtomicStore returns new AtomicStore[T].
func (*AtomicStore[T]) Exec ¶
func (s *AtomicStore[T]) Exec(ctx context.Context, op pkgstore.AtomicOperation[T]) (err error)
Exec runs an atomic operation.
type Database ¶
type Database interface { Beginner TableOperator }
Database represents a database connection.
type Execer ¶
type Execer interface {
ExecContext(ctx context.Context, sql string, arguments ...any) (sql.Result, error)
}
Execer executes a query without returning sql rows.
type MigrationFormat ¶
type MigrationFormat int8
MigrationFormat is a format used to create the migration files.
MigrationFileStyleGoMigrate uses the format: {version}_{title}.up.{extension} {version}_{title}.down.{extension}
MigrationFileStyleFlyway uses the format: {V}{version}__{migration_name}.sql – for Up migrations. {U}{version}__{migration_name}.sql – for down migrations.
ENUM( flyway gomigrate )
const ( // MigrationFormatFlyway is a MigrationFormat of type Flyway. MigrationFormatFlyway MigrationFormat = iota // MigrationFormatGomigrate is a MigrationFormat of type Gomigrate. MigrationFormatGomigrate )
func ParseMigrationFormat ¶
func ParseMigrationFormat(name string) (MigrationFormat, error)
ParseMigrationFormat attempts to convert a string to a MigrationFormat.
func (MigrationFormat) IsValid ¶
func (x MigrationFormat) IsValid() bool
IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values
func (MigrationFormat) MarshalText ¶
func (x MigrationFormat) MarshalText() ([]byte, error)
MarshalText implements the text marshaller method.
func (*MigrationFormat) Scan ¶
func (x *MigrationFormat) Scan(value interface{}) (err error)
Scan implements the Scanner interface.
func (MigrationFormat) String ¶
func (x MigrationFormat) String() string
String implements the Stringer interface.
func (*MigrationFormat) UnmarshalText ¶
func (x *MigrationFormat) UnmarshalText(text []byte) error
UnmarshalText implements the text unmarshaller method.
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator is Postgres database schem migrator.
func NewMigrator ¶
func NewMigrator(cfg MigratorConfig) (*Migrator, error)
NewMigrator returns a new Migrator.
func (*Migrator) MigrateDown ¶
MigrateDown applies down migrations.
type MigratorConfig ¶
type MigratorConfig struct { // MigrationsDir is a path to the migrations directory. If MigrationsFs is nil, the Migrator will use it directly. // If MigrationsFs is not nil, the path in MigrationsDir is used to strip the prefix. // // Example: // // //go:embed migrations/* // var MigrationsFS embed.FS // // Here, 'migrations' is a prefix that should be stripped from the path. // This allows the iofs.Driver to read its content correctly. MigrationsDir string MigrationsFs fs.FS DSN string Format MigrationFormat }
type NewStoreFunc ¶
type NewStoreFunc[T any] func(db Database, to TableOperator) T
type Querier ¶
type Querier interface {
QueryContext(ctx context.Context, sql string, args ...any) (*sql.Rows, error)
}
Querier runs a single SQL query.
type Rollbacker ¶
type Rollbacker interface {
Rollback() error
}
Rollbacker rollbacks a transaction.
type TableOperator ¶
TableOperator can run Exec and Query operations on database.
type Transactor ¶
type Transactor interface { Committer Rollbacker }
Transactor commits or rollbacks a transaction.