pgmfx

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ErrorPoolStatus = "ERR_P"
View Source
const ErrorQueryStatus = "ERR_Q"
View Source
const ErrorRowsReadStatus = "ERR_R"
View Source
const ErrorStatus = "ERR"
View Source
const OKStatus = "OK"

Variables

View Source
var ErrGetJsonFail = fmt.Errorf("fail to get json")
View Source
var ErrPgxMFHubClosePoint = fmt.Errorf("close point in hub")
View Source
var ErrQueryCall = fmt.Errorf("call request fail")
View Source
var ErrQueryPoolGet = fmt.Errorf("get free connection fail")
View Source
var ErrRowsProcess = fmt.Errorf("rows process fail")
View Source
var ErrUnmarshalJsonFail = fmt.Errorf("fail json unmarshal")

Functions

func RowsProcessNoRows

func RowsProcessNoRows(rows pgx.Rows) error

func WriteMetricDoReadResponce

func WriteMetricDoReadResponce(mp MetricsProvider, mRequest time.Time, poolName, sqlName string, resultResult string)

func WriteMetricDoRequest

func WriteMetricDoRequest(mp MetricsProvider, mRequest time.Time, poolName, sqlName string, resultResult string)

func WriteMetricGetPool

func WriteMetricGetPool(mp MetricsProvider, mRequest time.Time, poolName, sqlName string, resultResult string)

func WriteMetricRequest

func WriteMetricRequest(mp MetricsProvider, poolName, sqlName string)

func WriteMetricResponce

func WriteMetricResponce(mp MetricsProvider, mRequest time.Time, poolName, sqlName string, resultResult string)

Types

type ConnectConfig

type ConnectConfig struct {
	ConnString     string `envconfig:"conn_string" default:"user=postgres host=localhost port=5432 dbname=postgres" json:"conn_string"`
	Password       string `envconfig:"password" default_pwd:"postgres" json:"password"`
	MaxConnections int    `envconfig:"max_connections" default:"5" json:"max_connections"`
	MinConnections int    `envconfig:"min_connections" default:"0" json:"min_connections"`
	// OpenTimeout time in open state; 0 mean forever open
	OpenTimeout              time.Duration `envconfig:"open_timeout" default:"600s" json:"open_timeout"`
	IdleTimeout              time.Duration `envconfig:"idle_timeout" default:"600s" json:"idle_timeout"`
	PoolGetConnectionTimeout time.Duration `envconfig:"get_connection_timeout" default:"5s" json:"get_connection_timeout"`
	PoolName                 string        `envconfig:"pool_name" json:"pool_name"`
}

ConnectConfig connection config and pool config

func (*ConnectConfig) FeelCfg added in v1.0.0

func (cfg *ConnectConfig) FeelCfg(ctxIn context.Context, cfgRaw *oncfg.ConfigRaw) (err error)

func (*ConnectConfig) MakeConnection

func (cfg *ConnectConfig) MakeConnection(ctxIn context.Context) (cnct *poh.Connection[*pgx.Conn], err error)

func (*ConnectConfig) MakePool

func (cfg *ConnectConfig) MakePool(ctxBase context.Context, ctxClose context.CancelCauseFunc) (pool *PgxMFPool, err error)

type MetricsProvider

type MetricsProvider interface {
	WriteMetricRequest(poolName, sqlName string)
	WriteMetricGetPool(mRequest time.Time, poolName, sqlName string, resultResult string)
	WriteMetricDoRequest(mRequest time.Time, poolName, sqlName string, resultResult string)
	WriteMetricDoReadResponce(mRequest time.Time, poolName, sqlName string, resultResult string)
	WriteMetricResponce(mRequest time.Time, poolName, sqlName string, resultResult string)
}
var DefaultMetricsProvider MetricsProvider

type PgxMFHub added in v1.0.0

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

func MakePgxMFHub added in v1.0.0

func MakePgxMFHub(ctxBase context.Context) *PgxMFHub

func (*PgxMFHub) Cfg added in v1.0.0

func (pgxhub *PgxMFHub) Cfg() *oncfg.ListSourceConfig

func (*PgxMFHub) Close added in v1.0.0

func (pgxhub *PgxMFHub) Close(err error)

Close - calls ctxClose if its set (error should be set)

func (*PgxMFHub) Get added in v1.0.0

func (pgxhub *PgxMFHub) Get(key string) (point *PgxMFPool, ok bool)

type PgxMFPool

type PgxMFPool struct {
	Pool                    *poh.ConnectionPool[*pgx.Conn]
	PoolName                func() string
	MetricsProvider         MetricsProvider
	GetNewConnectionTimeout poh.ExpireDurationFunc
	// contains filtered or unexported fields
}

func (PgxMFPool) Cfg added in v1.0.0

func (pool PgxMFPool) Cfg() *ConnectConfig

func (PgxMFPool) Query

func (pool PgxMFPool) Query(ctxIn context.Context, rp RowsProcess, sqlName string, sql string, args ...any) (err error)

type RowsProcess

type RowsProcess func(rows pgx.Rows) error

func RowsProcessJson

func RowsProcessJson(js *json.RawMessage, exists *bool) RowsProcess

func RowsProcessStructFronJson

func RowsProcessStructFronJson[T any](objs *[]T, exists *bool) RowsProcess

Directories

Path Synopsis
examples
common command
config_load command
conn_hub command

Jump to

Keyboard shortcuts

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