postgres

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2025 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(ctx context.Context, log *slog.Logger, cfg *Config) (pool *pgxpool.Pool, err error)

NewClient создает и конфигурирует пул соединений.

Types

type Config

type Config struct {
	Username string
	Password string
	Host     string
	Port     string
	Database string

	ConnAmount        *int32
	MinConnAmount     *int32
	MaxConnIdleTime   *time.Duration
	MaxConnLifetime   *time.Duration
	HealthCheckPeriod *time.Duration
	AcquireTimeout    time.Duration
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(username, password, host, port, database string) *Config

func (*Config) WithAcquireTimeout

func (c *Config) WithAcquireTimeout(d time.Duration) *Config

func (*Config) WithConnAmount

func (c *Config) WithConnAmount(amount int32) *Config

func (*Config) WithHealthCheckPeriod

func (c *Config) WithHealthCheckPeriod(d time.Duration) *Config

func (*Config) WithMaxConnAttempts

func (c *Config) WithMaxConnAttempts(attempts int) *Config

func (*Config) WithMaxConnIdleTime

func (c *Config) WithMaxConnIdleTime(d time.Duration) *Config

func (*Config) WithMaxConnLifetime

func (c *Config) WithMaxConnLifetime(d time.Duration) *Config

func (*Config) WithMinConnAmount

func (c *Config) WithMinConnAmount(amount int32) *Config

func (*Config) WithRetryConnDelay

func (c *Config) WithRetryConnDelay(delay time.Duration) *Config

func (*Config) WithTracer

func (c *Config) WithTracer(tracer pgx.QueryTracer) *Config

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

func NewMigrator

func NewMigrator(db *pgxpool.Pool, migrationsDir string) (*Migrator, error)

func (*Migrator) Up

type Postgres

type Postgres interface {
	Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
	QueryRow(ctx context.Context, query string, args ...interface{}) pgx.Row
	Exec(ctx context.Context, query string, args ...interface{}) (commandTag pgconn.CommandTag, err error)

	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (txman.Tx, error)

	Pool() *pgxpool.Pool

	Close()
}

func NewPostgres

func NewPostgres(ctx context.Context, log *slog.Logger, cfg *Config) (Postgres, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL