pgxpool

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTransaction

func CreateTransaction(
	pool *pgxpool.Pool,
	fn func(ctx context.Context, tx pgx.Tx) error,
) error

CreateTransaction creates a transaction for the database

func CreateTransactionWithCtx

func CreateTransactionWithCtx(
	ctx context.Context,
	pool *pgxpool.Pool,
	fn func(ctx context.Context, tx pgx.Tx) error,
) error

CreateTransactionWithCtx creates a transaction for the database with context

Types

type Config

type Config interface {
	DataSourceName() string
	MaxOpenConnections() int
	MaxIdleConnections() int
	ConnectionMaxLifetime() time.Duration
	ConnectionMaxIdleTime() time.Duration
	HealthCheckPeriod() time.Duration
	ConnectionMaxLifetimeJitter() time.Duration
	ParsedConfig() (*pgxpool.Config, error)
}

Config interface

type DefaultPoolHandler

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

DefaultPoolHandler struct

func NewDefaultPoolHandler

func NewDefaultPoolHandler(
	config Config,
) (*DefaultPoolHandler, error)

NewDefaultPoolHandler creates a new connection

func (*DefaultPoolHandler) Connect

func (d *DefaultPoolHandler) Connect() (*pgxpool.Pool, error)

Connect returns a new connection pool

func (*DefaultPoolHandler) Disconnect

func (d *DefaultPoolHandler) Disconnect()

Disconnect closes the connection pool

func (*DefaultPoolHandler) Pool

func (d *DefaultPoolHandler) Pool() (*pgxpool.Pool, error)

Pool returns the connection pool

type DefaultService

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

DefaultService is the default service struct

func NewDefaultService

func NewDefaultService(pool *pgxpool.Pool) (
	instance *DefaultService,
	err error,
)

NewDefaultService creates a new default service

func (*DefaultService) ClearStatTicker added in v0.5.6

func (d *DefaultService) ClearStatTicker()

ClearStatTicker clears the stat ticker

func (*DefaultService) CreateTransaction

func (d *DefaultService) CreateTransaction(
	fn func(
		ctx context.Context,
		tx pgx.Tx,
	) error,
) error

CreateTransaction creates a transaction for the database

func (*DefaultService) CreateTransactionWithCtx

func (d *DefaultService) CreateTransactionWithCtx(
	ctx context.Context,
	fn func(ctx context.Context, tx pgx.Tx) error,
) error

CreateTransactionWithCtx creates a transaction for the database with a context

func (*DefaultService) Exec

func (d *DefaultService) Exec(query *string, params ...interface{}) (
	*pgconn.CommandTag,
	error,
)

Exec executes a query with parameters and returns the result

func (*DefaultService) ExecWithCtx

func (d *DefaultService) ExecWithCtx(
	ctx context.Context,
	query *string,
	params ...interface{},
) (
	*pgconn.CommandTag,
	error,
)

ExecWithCtx executes a query with parameters and returns the result with a context

func (*DefaultService) Migrate

func (d *DefaultService) Migrate(queries ...string) error

Migrate migrates the database

func (*DefaultService) Pool

func (d *DefaultService) Pool() *pgxpool.Pool

Pool returns the pool

func (*DefaultService) Query added in v0.5.4

func (d *DefaultService) Query(
	query *string,
	params ...interface{},
) (pgx.Rows, error)

Query runs a query with parameters and returns the result

func (*DefaultService) QueryRow

func (d *DefaultService) QueryRow(
	query *string,
	params ...interface{},
) pgx.Row

QueryRow runs a query row with parameters and returns the result row

func (*DefaultService) QueryRowWithCtx

func (d *DefaultService) QueryRowWithCtx(
	ctx context.Context,
	query *string,
	params ...interface{},
) pgx.Row

QueryRowWithCtx runs a query row with parameters and returns the result row with a context

func (*DefaultService) QueryWithCtx added in v0.5.4

func (d *DefaultService) QueryWithCtx(
	ctx context.Context,
	query *string,
	params ...interface{},
) (pgx.Rows, error)

QueryWithCtx runs a query with parameters and returns the result with a context

func (*DefaultService) ScanRow

func (d *DefaultService) ScanRow(
	row pgx.Row,
	destinations ...interface{},
) error

ScanRow scans a row

func (*DefaultService) SetStatTicker added in v0.5.6

func (d *DefaultService) SetStatTicker(
	duration time.Duration,
	fn func(*pgxpool.Stat),
)

SetStatTicker sets a stat ticker

type PoolConfig

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

PoolConfig struct

func NewPoolConfig

func NewPoolConfig(
	dataSourceName string,
	maxOpenConnections,
	maxIdleConnections int,
	connectionMaxIdleTime,
	connectionMaxLifetime,
	healthCheckPeriod,
	connectionMaxLifetimeJitter time.Duration,
) (*PoolConfig, error)

NewPoolConfig creates a new pool configuration

func (*PoolConfig) ConnectionMaxIdleTime

func (p *PoolConfig) ConnectionMaxIdleTime() time.Duration

ConnectionMaxIdleTime returns the connection max idle time

func (*PoolConfig) ConnectionMaxLifetime

func (p *PoolConfig) ConnectionMaxLifetime() time.Duration

ConnectionMaxLifetime returns the connection max lifetime

func (*PoolConfig) ConnectionMaxLifetimeJitter

func (p *PoolConfig) ConnectionMaxLifetimeJitter() time.Duration

ConnectionMaxLifetimeJitter returns the connection max lifetime jitter

func (*PoolConfig) DataSourceName

func (p *PoolConfig) DataSourceName() string

DataSourceName returns the data source name

func (*PoolConfig) HealthCheckPeriod

func (p *PoolConfig) HealthCheckPeriod() time.Duration

HealthCheckPeriod returns the health check period

func (*PoolConfig) MaxIdleConnections

func (p *PoolConfig) MaxIdleConnections() int

MaxIdleConnections returns the maximum idle connections

func (*PoolConfig) MaxOpenConnections

func (p *PoolConfig) MaxOpenConnections() int

MaxOpenConnections returns the maximum open connections

func (*PoolConfig) ParsedConfig

func (p *PoolConfig) ParsedConfig() (*pgxpool.Config, error)

ParsedConfig returns the parsed configuration

type PoolHandler

type PoolHandler interface {
	Connect() (*pgxpool.Pool, error)
	Pool() (*pgxpool.Pool, error)
	Disconnect()
}

PoolHandler interface

type Service

type Service interface {
	Pool() *pgxpool.Pool
	Migrate(queries ...string) error
	CreateTransaction(fn func(ctx context.Context, tx pgx.Tx) error) error
	CreateTransactionWithCtx(
		ctx context.Context,
		fn func(ctx context.Context, tx pgx.Tx) error,
	) error
	Exec(query *string, params ...interface{}) (*pgconn.CommandTag, error)
	ExecWithCtx(
		ctx context.Context,
		query *string,
		params ...interface{},
	) (*pgconn.CommandTag, error)
	Query(query *string, params ...interface{}) (pgx.Rows, error)
	QueryWithCtx(
		ctx context.Context,
		query *string,
		params ...interface{},
	) (pgx.Rows, error)
	QueryRow(query *string, params ...interface{}) pgx.Row
	QueryRowWithCtx(
		ctx context.Context,
		query *string,
		params ...interface{},
	) pgx.Row
	ScanRow(row pgx.Row, destinations ...interface{}) error
	SetStatTicker(
		duration time.Duration,
		fn func(*pgxpool.Stat),
	)
	ClearStatTicker()
}

Service is the interface for the service

Jump to

Keyboard shortcuts

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