common

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigurePGXLogger

func ConfigurePGXLogger(connConfig *pgx.ConnConfig)

ConfigurePGXLogger sets zerolog global logger into the connection pool configuration, and maps info level events to debug, as they are rather verbose for SpiceDB's info level

func ConvertToWriteConstraintError

func ConvertToWriteConstraintError(livingTupleConstraint string, err error) error

ConvertToWriteConstraintError converts the given Postgres error into a CreateRelationshipExistsError if applicable. If not applicable, returns nils.

func NewPGXExecutor

func NewPGXExecutor(txSource TxFactory) common.ExecuteQueryFunc

NewPGXExecutor creates an executor that uses the pgx library to make the specified queries.

Types

type ConnPooler added in v1.18.1

type ConnPooler interface {
	Querier
	Begin(ctx context.Context) (pgx.Tx, error)
	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
	Close()
}

ConnPooler is an interface to pgx.Pool methods used by postgres-based datastores

func MustNewInterceptorPooler added in v1.18.1

func MustNewInterceptorPooler(pooler ConnPooler, interceptor QueryInterceptor) ConnPooler

type DBReader added in v1.18.1

type DBReader interface {
	Exec(ctx context.Context, sql string, arguments ...interface{}) (commandTag pgconn.CommandTag, err error)
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
}

DBReader copies enough of the common interface between pgxpool and tx to be useful

type InterceptorPooler added in v1.18.1

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

func (InterceptorPooler) Begin added in v1.18.1

func (i InterceptorPooler) Begin(ctx context.Context) (pgx.Tx, error)

func (InterceptorPooler) BeginTx added in v1.18.1

func (i InterceptorPooler) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)

func (InterceptorPooler) Close added in v1.18.1

func (i InterceptorPooler) Close()

func (InterceptorPooler) Exec added in v1.18.1

func (i InterceptorPooler) Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)

func (InterceptorPooler) Query added in v1.18.1

func (i InterceptorPooler) Query(ctx context.Context, sql string, optionsAndArgs ...any) (pgx.Rows, error)

func (InterceptorPooler) QueryRow added in v1.18.1

func (i InterceptorPooler) QueryRow(ctx context.Context, sql string, optionsAndArgs ...any) pgx.Row

type PoolOptions added in v1.18.0

type PoolOptions struct {
	ConnMaxIdleTime         *time.Duration
	ConnMaxLifetime         *time.Duration
	ConnMaxLifetimeJitter   *time.Duration
	ConnHealthCheckInterval *time.Duration
	MinOpenConns            *int
	MaxOpenConns            *int
}

PoolOptions is the set of configuration used for a pgx connection pool.

func (PoolOptions) ConfigurePgx added in v1.18.0

func (opts PoolOptions) ConfigurePgx(pgxConfig *pgxpool.Config)

ConfigurePgx applies PoolOptions to a pgx connection pool confiugration.

type Querier added in v1.19.0

type Querier interface {
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
	Query(ctx context.Context, sql string, optionsAndArgs ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, optionsAndArgs ...any) pgx.Row
}

Querier holds common methods for connections and pools, equivalent to Querier (which is deprecated for pgx v5)

type QueryInterceptor added in v1.18.1

type QueryInterceptor interface {
	// InterceptExec is the method to intercept Querier.Exec. The implementation is responsible to invoke the
	// delegate with the provided arguments
	InterceptExec(ctx context.Context, delegate Querier, sql string, arguments ...any) (pgconn.CommandTag, error)

	// InterceptQuery is the method to intercept Querier.Query. The implementation is responsible to invoke the
	// delegate with the provided arguments
	InterceptQuery(ctx context.Context, delegate Querier, sql string, args ...any) (pgx.Rows, error)

	// InterceptQueryRow is the method to intercept Querier.QueryRow. The implementation is responsible to invoke the
	// delegate with the provided arguments
	InterceptQueryRow(ctx context.Context, delegate Querier, sql string, optionsAndArgs ...any) pgx.Row
}

QueryInterceptor exposes a mechanism to intercept all methods exposed in Querier This can be used as a sort of middleware layer for pgx queries

type TxFactory

type TxFactory func(context.Context) (DBReader, common.TxCleanupFunc, error)

TxFactory returns a transaction, cleanup function, and any errors that may have occurred when building the transaction.

Jump to

Keyboard shortcuts

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