pginit

package
v0.0.0-...-3014034 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	User         string
	Password     string
	Host         string
	Port         string
	Database     string
	MaxConns     int32
	MaxIdleConns int32
	MaxLifeTime  time.Duration
}

type Option

type Option func(*PGInit)

Option configures PGInit behavior.

func WithCustomTypes

func WithCustomTypes(types []string) Option

func WithDecimalType

func WithDecimalType() Option

WithDecimalType set pgx decimal type to ericlagergren/decimal.

func WithLogLevel

func WithLogLevel(zLvl zerolog.Level) Option

WithLogLevel set pgx log level.

func WithLogger

func WithLogger(logger *zerolog.Logger, reqIDKeyFromCtx interface{}) Option

WithLogger Add logger to pgx. if the request context contains request id, can pass in the request id context key to reqIDKeyFromCtx and logger will log with the request id. Only will log if the log level is equal and above pgx.LogLevelWarn.

func WithTracer

func WithTracer(tracer pgx.QueryTracer) Option

WithTracer set pgx tracer.

func WithUUIDType

func WithUUIDType() Option

WithUUIDType set pgx uuid type to gofrs/uuid.

type PGInit

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

PGInit provides capabilities for connect to postgres with pgx.pool.

func New

func New(conf *Config, opts ...Option) (*PGInit, error)

New initializes a PGInit using the provided Config and options. If opts is not provided it will initializes PGInit with default configuration.

func (*PGInit) ConnConfig

func (pgi *PGInit) ConnConfig() *pgx.ConnConfig

func (*PGInit) ConnPool

func (pgi *PGInit) ConnPool(ctx context.Context) (*pgxpool.Pool, error)

ConnPool initiates connection to database and return a pgxpool.Pool.

Directories

Path Synopsis
ext

Jump to

Keyboard shortcuts

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