common

package
v1.22.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BulkLoad added in v1.22.0

func BulkLoad(
	ctx context.Context,
	tx pgx.Tx,
	tupleTableName string,
	colNames []string,
	iter datastore.BulkWriteRelationshipSource,
) (uint64, error)

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(querier DBFuncQuerier) 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)
	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, 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 DBFuncQuerier added in v1.22.0

type DBFuncQuerier interface {
	ExecFunc(ctx context.Context, tagFunc func(ctx context.Context, tag pgconn.CommandTag, err error) error, sql string, arguments ...any) error
	QueryFunc(ctx context.Context, rowsFunc func(ctx context.Context, rows pgx.Rows) error, sql string, optionsAndArgs ...any) error
	QueryRowFunc(ctx context.Context, rowFunc func(ctx context.Context, row pgx.Row) error, sql string, optionsAndArgs ...any) error
}

DBFuncQuerier is satisfied by RetryPool and QuerierFuncs (which can wrap a pgxpool or transaction)

func QuerierFuncsFor added in v1.22.0

func QuerierFuncsFor(d Querier) DBFuncQuerier

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) CopyFrom added in v1.22.0

func (i InterceptorPooler) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)

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 QuerierFuncs added in v1.22.0

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

func (*QuerierFuncs) ExecFunc added in v1.22.0

func (t *QuerierFuncs) ExecFunc(ctx context.Context, tagFunc func(ctx context.Context, tag pgconn.CommandTag, err error) error, sql string, arguments ...any) error

func (*QuerierFuncs) QueryFunc added in v1.22.0

func (t *QuerierFuncs) QueryFunc(ctx context.Context, rowsFunc func(ctx context.Context, rows pgx.Rows) error, sql string, optionsAndArgs ...any) error

func (*QuerierFuncs) QueryRowFunc added in v1.22.0

func (t *QuerierFuncs) QueryRowFunc(ctx context.Context, rowFunc func(ctx context.Context, row pgx.Row) error, sql string, optionsAndArgs ...any) error

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

Jump to

Keyboard shortcuts

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