Documentation
¶
Index ¶
- Constants
- func Register()
- func ServiceFactory(params map[string]any) any
- type Config
- type PgxPostgresPool
- func (p *PgxPostgresPool) Acquire(ctx context.Context) (serviceapi.DbConn, error)
- func (p *PgxPostgresPool) Begin(ctx context.Context) (serviceapi.DbTx, error)
- func (p *PgxPostgresPool) Exec(ctx context.Context, query string, args ...any) (serviceapi.CommandResult, error)
- func (p *PgxPostgresPool) IsErrorNoRows(err error) bool
- func (p *PgxPostgresPool) IsExists(ctx context.Context, query string, args ...any) (bool, error)
- func (p *PgxPostgresPool) Ping(ctx context.Context) error
- func (p *PgxPostgresPool) Query(ctx context.Context, query string, args ...any) (serviceapi.Rows, error)
- func (p *PgxPostgresPool) QueryRow(ctx context.Context, query string, args ...any) serviceapi.Row
- func (p *PgxPostgresPool) Release() error
- func (p *PgxPostgresPool) SelectManyRowMap(ctx context.Context, query string, args ...any) ([]serviceapi.RowMap, error)
- func (p *PgxPostgresPool) SelectManyWithMapper(ctx context.Context, fnScan func(serviceapi.Row) (any, error), query string, ...) (any, error)
- func (p *PgxPostgresPool) SelectMustOne(ctx context.Context, query string, args []any, dest ...any) error
- func (p *PgxPostgresPool) SelectOne(ctx context.Context, query string, args []any, dest ...any) error
- func (p *PgxPostgresPool) SelectOneRowMap(ctx context.Context, query string, args ...any) (serviceapi.RowMap, error)
- func (p *PgxPostgresPool) SetSchemaRls(schema string, rlsContext map[string]string)
- func (p *PgxPostgresPool) Shutdown() error
- func (p *PgxPostgresPool) Transaction(ctx context.Context, fn func(tx serviceapi.DbExecutor) error) error
Constants ¶
const SERVICE_TYPE = "dbpool_pg"
for single service module, module name equals service name
Variables ¶
This section is empty.
Functions ¶
func ServiceFactory ¶ added in v0.3.0
Types ¶
type Config ¶ added in v0.2.4
type Config struct {
DSN string `json:"dsn" yaml:"dsn"`
Host string `json:"host" yaml:"host"`
Port int `json:"port" yaml:"port"`
Database string `json:"database" yaml:"database"`
Username string `json:"username" yaml:"username"`
Password string `json:"password" yaml:"password"`
MinConns int `json:"min-cons" yaml:"min-cons"`
MaxConns int `json:"max-cons" yaml:"max-cons"`
MaxIdleTime time.Duration `json:"max-idle-time" yaml:"max-idle-time"`
MaxLifetime time.Duration `json:"max-lifetime" yaml:"max-lifetime"`
SSLMode string `json:"sslmode" yaml:"sslmode"`
Schema string `json:"schema" yaml:"schema"`
RlsContext map[string]string `json:"rls-context" yaml:"rls-context"`
}
Config represents the configuration for the PostgreSQL connection pool service. It can be provided in various formats, including a DSN string, a map, or a struct. If using DSN, it should be in the format: postgres://username:password@host:port/database?sslmode=disable&pool_min_conns=0&pool_max_conns=4&pool_max_conn_idle_time=30m&pool_max_conn_lifetime=1h Host, Port, Database, Username, and Password can be provided separately if DSN is not used. Other parameters like MinConnections, MaxConnections, MaxIdleTime, MaxLifetime, and SSLMode can also be set.
func (*Config) GetFinalDSN ¶ added in v0.3.0
type PgxPostgresPool ¶ added in v0.9.3
type PgxPostgresPool struct {
Dsn string
Schema string
RlsContext map[string]string
// contains filtered or unexported fields
}
func NewPgxPostgresPool ¶
func Service ¶ added in v0.3.0
func Service(poolName string, cfg *Config) *PgxPostgresPool
func (*PgxPostgresPool) Acquire ¶ added in v0.9.3
func (p *PgxPostgresPool) Acquire(ctx context.Context) (serviceapi.DbConn, error)
func (*PgxPostgresPool) Begin ¶ added in v0.9.3
func (p *PgxPostgresPool) Begin(ctx context.Context) (serviceapi.DbTx, error)
Begin implements serviceapi.DbPool.
func (*PgxPostgresPool) Exec ¶ added in v0.9.3
func (p *PgxPostgresPool) Exec(ctx context.Context, query string, args ...any) (serviceapi.CommandResult, error)
Exec implements serviceapi.DbPool.
func (*PgxPostgresPool) IsErrorNoRows ¶ added in v0.9.3
func (p *PgxPostgresPool) IsErrorNoRows(err error) bool
IsErrorNoRows implements serviceapi.DbPool.
func (*PgxPostgresPool) Ping ¶ added in v0.9.3
func (p *PgxPostgresPool) Ping(ctx context.Context) error
Ping implements serviceapi.DbPool.
func (*PgxPostgresPool) Query ¶ added in v0.9.3
func (p *PgxPostgresPool) Query(ctx context.Context, query string, args ...any) (serviceapi.Rows, error)
Query implements serviceapi.DbPool.
func (*PgxPostgresPool) QueryRow ¶ added in v0.9.3
func (p *PgxPostgresPool) QueryRow(ctx context.Context, query string, args ...any) serviceapi.Row
QueryRow implements serviceapi.DbPool.
func (*PgxPostgresPool) Release ¶ added in v0.9.3
func (p *PgxPostgresPool) Release() error
Release implements serviceapi.DbPool.
func (*PgxPostgresPool) SelectManyRowMap ¶ added in v0.9.3
func (p *PgxPostgresPool) SelectManyRowMap(ctx context.Context, query string, args ...any) ([]serviceapi.RowMap, error)
SelectManyRowMap implements serviceapi.DbPool.
func (*PgxPostgresPool) SelectManyWithMapper ¶ added in v0.9.3
func (p *PgxPostgresPool) SelectManyWithMapper(ctx context.Context, fnScan func(serviceapi.Row) (any, error), query string, args ...any) (any, error)
SelectManyWithMapper implements serviceapi.DbPool.
func (*PgxPostgresPool) SelectMustOne ¶ added in v0.9.3
func (p *PgxPostgresPool) SelectMustOne(ctx context.Context, query string, args []any, dest ...any) error
SelectMustOne implements serviceapi.DbPool.
func (*PgxPostgresPool) SelectOne ¶ added in v0.9.3
func (p *PgxPostgresPool) SelectOne(ctx context.Context, query string, args []any, dest ...any) error
SelectOne implements serviceapi.DbPool.
func (*PgxPostgresPool) SelectOneRowMap ¶ added in v0.9.3
func (p *PgxPostgresPool) SelectOneRowMap(ctx context.Context, query string, args ...any) (serviceapi.RowMap, error)
SelectOneRowMap implements serviceapi.DbPool.
func (*PgxPostgresPool) SetSchemaRls ¶ added in v0.9.3
func (p *PgxPostgresPool) SetSchemaRls(schema string, rlsContext map[string]string)
SetSchemaRls implements serviceapi.DbPoolSchemaRls.
func (*PgxPostgresPool) Shutdown ¶ added in v0.9.3
func (p *PgxPostgresPool) Shutdown() error
Shutdown implements serviceapi.DbPool.
func (*PgxPostgresPool) Transaction ¶ added in v0.9.3
func (p *PgxPostgresPool) Transaction(ctx context.Context, fn func(tx serviceapi.DbExecutor) error) error
Transaction implements serviceapi.DbPool.