Documentation
¶
Index ¶
- func CreateTransaction(pool *pgxpool.Pool, fn func(ctx context.Context, tx pgx.Tx) error) error
- func CreateTransactionWithCtx(ctx context.Context, pool *pgxpool.Pool, ...) error
- type Config
- type DefaultPoolHandler
- type DefaultService
- func (d *DefaultService) ClearStatTicker()
- func (d *DefaultService) CreateTransaction(fn func(ctx context.Context, tx pgx.Tx) error) error
- func (d *DefaultService) CreateTransactionWithCtx(ctx context.Context, fn func(ctx context.Context, tx pgx.Tx) error) error
- func (d *DefaultService) Exec(query *string, params ...interface{}) (*pgconn.CommandTag, error)
- func (d *DefaultService) ExecWithCtx(ctx context.Context, query *string, params ...interface{}) (*pgconn.CommandTag, error)
- func (d *DefaultService) Migrate(queries ...string) error
- func (d *DefaultService) Pool() *pgxpool.Pool
- func (d *DefaultService) Query(query *string, params ...interface{}) (pgx.Rows, error)
- func (d *DefaultService) QueryRow(query *string, params ...interface{}) pgx.Row
- func (d *DefaultService) QueryRowWithCtx(ctx context.Context, query *string, params ...interface{}) pgx.Row
- func (d *DefaultService) QueryWithCtx(ctx context.Context, query *string, params ...interface{}) (pgx.Rows, error)
- func (d *DefaultService) ScanRow(row pgx.Row, destinations ...interface{}) error
- func (d *DefaultService) SetStatTicker(duration time.Duration, fn func(*pgxpool.Stat))
- type PoolConfig
- func (p *PoolConfig) ConnectionMaxIdleTime() time.Duration
- func (p *PoolConfig) ConnectionMaxLifetime() time.Duration
- func (p *PoolConfig) ConnectionMaxLifetimeJitter() time.Duration
- func (p *PoolConfig) DataSourceName() string
- func (p *PoolConfig) HealthCheckPeriod() time.Duration
- func (p *PoolConfig) MaxIdleConnections() int
- func (p *PoolConfig) MaxOpenConnections() int
- func (p *PoolConfig) ParsedConfig() (*pgxpool.Config, error)
- type PoolHandler
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTransaction ¶
CreateTransaction creates a transaction for the database
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
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) 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