Documentation
¶
Overview ¶
Package dbx extends the db package with additional features including automatic schema creation, database migrations via goose, and connection pool configuration. It provides a higher-level database client for PostgreSQL.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client wraps a db.Client with migration support and schema management. It is safe for concurrent use.
func Open ¶
Open establishes a connection to a PostgreSQL database using the provided configuration. It applies connection pool settings, creates the schema if needed, and runs migrations. Returns an error if the connection fails, schema creation fails, or migrations fail. nolint:cyclop,nonamedreturns
type Config ¶
type Config struct {
Host string `validate:"required" schema:"Хост"`
Port int `validate:"required" schema:"Порт"`
Database string `validate:"required" schema:"База данных"`
Username string `schema:"Логин"`
Password string `schema:"Пароль"`
Schema string `schema:"Схема"`
MaxOpenConn int `` /* 176-byte string literal not displayed */
Params map[string]string `schema:"Дополнительные параметры подключения"`
}
Config holds the configuration for establishing a database connection.
type LogTracer ¶
type LogTracer struct {
// contains filtered or unexported fields
}
LogTracer is a pgx QueryTracer that logs queries at debug level.
func NewLogTracer ¶
NewLogTracer creates a new LogTracer with the provided logger.
func (LogTracer) TraceQueryEnd ¶
TraceQueryEnd is called when a query completes. Currently a no-op.
type MigrationRunner ¶
type MigrationRunner interface {
Run(ctx context.Context, db *sql.DB, gooseOpts ...goose.ProviderOption) error
}
MigrationRunner defines the interface for running database migrations.
type Option ¶
type Option func(db *Client)
Option is a function that configures a Client.
func WithApplicationName ¶ added in v1.52.2
WithApplicationName sets the application name connection parameter. This is used for identification in database logs and monitoring.
func WithCreateSchema ¶ added in v1.50.1
WithCreateSchema enables automatic creation of the database schema if it does not exist. This only applies to non-read-only connections with a custom schema.
func WithMigrationRunner ¶
WithMigrationRunner configures the client to run database migrations from the specified directory. The logger is used for migration-related logging.
func WithQueryTracer ¶
func WithQueryTracer(tracers ...pgx.QueryTracer) Option
WithQueryTracer registers one or more pgx QueryTracers for query lifecycle events.