pgz

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initializer

func Initializer(ctx context.Context) (injectz.Injector, injectz.Releaser)

Initializer is a PG initializer.

func NewConfigSingletonInjector

func NewConfigSingletonInjector(cfg *Config) injectz.Injector

NewConfigSingletonInjector always inject the given *Config.

Types

type Config added in v1.1.0

type Config struct {
	PostgresURL           string `json:"postgresUrl" validate:"required,url"`
	EnableProxyMode       bool   `json:"proxyMode"`
	ConnectTimeoutSeconds uint32 `json:"connectTimeoutSeconds"`
}

Config describes the configuration for PG.

func GetConfig

func GetConfig(ctx context.Context) *Config

GetConfig extracts the *Config from context, panics if not found.

func (*Config) Validate added in v1.2.0

func (c *Config) Validate() error

Validate implements the vz.Validator interface.

type ContextPG

type ContextPG interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

ContextPG describes a PG with a cached context.

func GetCtx

func GetCtx(ctx context.Context) ContextPG

GetCtx extracts the PG from context and wraps it as ContextPG, panics if not found.

type PG

type PG interface {
	ContextPG
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
}

PG describes the pg module (a subset of *sql.DB).

func Get

func Get(ctx context.Context) PG

Get extracts the PG from context, panics if not found.

type Tx

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

Tx describes a transaction.

func NewTx

func NewTx(ctx context.Context) *Tx

NewTx initializes a new Tx.

func (*Tx) Run

func (t *Tx) Run(f func(ctx context.Context) error) error

Run runs the transaction.

func (*Tx) SetAllowReentrant

func (t *Tx) SetAllowReentrant(allowReentrant bool) *Tx

SetAllowReentrant sets the "allow reentrant" flag.

func (*Tx) SetIsolationLevel

func (t *Tx) SetIsolationLevel(isolationLevel sql.IsolationLevel) *Tx

SetIsolationLevel sets the isolation level.

func (*Tx) SetReadOnly

func (t *Tx) SetReadOnly(readOnly bool) *Tx

SetReadOnly sets the read only flag.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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