Documentation
¶
Index ¶
- func CopyAll[T any](connection Connection, ctx context.Context, tableName string, ...) (errorResult error)
- func CopyAny[T any](connection Connection, ctx context.Context, tableName string, ...) (int64, error)
- type Batch
- type CommandTag
- type CommandTagHandler
- type Config
- type Connection
- type Database
- type MigrationPlan
- type MigrationRecord
- type RowCollector
- type RowScanner
- type SliceMapper
- type Transaction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyAll ¶
func CopyAll[T any]( connection Connection, ctx context.Context, tableName string, columnNames []string, input []T, outputMapper SliceMapper[T], ) (errorResult error)
Types ¶
type Batch ¶
type Batch interface {
Exec(handler CommandTagHandler, sql string, args ...any)
Query(collector RowCollector, handler CommandTagHandler, sql string, args ...any)
QueryRow(collector RowCollector, sql string, args ...any)
Send() error
// contains filtered or unexported methods
}
type CommandTag ¶
type CommandTagHandler ¶
type CommandTagHandler func(ctx context.Context, tag CommandTag) error
type Config ¶
type Config struct {
Address string `env:"POSTGRES_ADDRESS" validate:"required,hostname_port"`
Username string `env:"POSTGRES_USER" validate:"required"`
Password string `env:"POSTGRES_PASSWORD" validate:"required"`
DatabaseName string `env:"POSTGRES_DB_NAME" validate:"required"`
LogLevel string `env:"POSTGRES_LOG_LEVEL" validate:"oneof=trace debug info warn error none" default:"info"`
MigrationTimeout uint `env:"POSTGRES_MIGRATION_TIMEOUT" default:"30"`
}
Config defines the options that are used when connecting to a PostgreSQL instance
type Connection ¶
type Connection interface {
// Begin starts a transaction.
Begin(ctx context.Context) (Transaction, error)
// Batch creates a batch of commands.
Batch(ctx context.Context) Batch
// Exec execute the command.
Exec(ctx context.Context, sql string, args ...any) (CommandTag, error)
// Query scan the result rows by calling the collector repeatedly.
Query(ctx context.Context, collector RowCollector, sql string, args ...any) (CommandTag, error)
// QueryRow expects the result is at most one row. Returns nil [RowScanner] if
// the result is empty.
QueryRow(ctx context.Context, sql string, args ...any) (RowScanner, error)
// contains filtered or unexported methods
}
type Database ¶
type Database interface {
Connection
// contains filtered or unexported methods
}
type MigrationPlan ¶
type MigrationPlan []MigrationRecord
type MigrationRecord ¶
type RowCollector ¶
type RowCollector func(ctx context.Context, row RowScanner) error
type RowScanner ¶
type SliceMapper ¶
type Transaction ¶
type Transaction interface {
Connection
// Finalize safely concludes a database transaction by either committing or
// rolling back. It rolls back the transaction if any of the following conditions
// are met: the input error is not null, a panic occurred earlier in execution,
// the provided context has an error (canceled or expired), or the commit
// operation itself fails. This ensures reliable and consistent transaction
// handling.
Finalize(ctx context.Context, errorResult *error)
}
Click to show internal directories.
Click to hide internal directories.