Documentation
¶
Overview ¶
Package postgres provides pool based operations on Postgres database.
Index ¶
- func CommitTx(ctx context.Context) error
- func InTx(ctx context.Context) bool
- func RollbackTx(ctx context.Context) error
- func Tx(ctx context.Context) pgx.Tx
- func WithTx[T any](ctx context.Context, pool *Database, fn func(ctx context.Context) (T, error)) (T, error)
- type Database
- func (p *Database) BeginTx(ctx context.Context) (context.Context, error)
- func (p *Database) Close()
- func (p *Database) Conn(ctx context.Context) (*pgxpool.Conn, error)
- func (p *Database) Handle() *sql.DB
- func (p *Database) Ping(ctx context.Context) error
- func (p *Database) Pool() *pgxpool.Pool
- func (p *Database) WithTx(ctx context.Context, fn func(ctx context.Context) error) error
- type Migrator
- type NewDatabaseParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RollbackTx ¶
RollbackTx rolls back the transaction stored in the context, if any.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is a handle to Postgres database with connection pool support.
func NewDatabase ¶
func NewDatabase(ctx context.Context, p *NewDatabaseParams) (*Database, error)
NewDatabase creates Database.
func (*Database) BeginTx ¶
BeginTx starts a new transaction and returns a new context containing the transaction.
func (*Database) Handle ¶
Handle returns an sql.DB instance for compatibility with database/sql package, acting as a connection handle.
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator is for managing migrations.
func NewMigrator ¶
NewMigrator creates a new Migrator. fs is assumed to be the root of the migration files that's flat.
func (*Migrator) MigrateDownAll ¶
MigrateDownAll rolls back all applied migrations in the database.
type NewDatabaseParams ¶
NewDatabaseParams of NewDatabase.