common

package
v1.35.2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 22 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 ConfigureOTELTracer added in v1.24.0

func ConfigureOTELTracer(connConfig *pgx.ConnConfig)

ConfigureOTELTracer adds OTEL tracing to a pgx.ConnConfig

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 ConnectWithInstrumentation added in v1.29.0

func ConnectWithInstrumentation(ctx context.Context, url string) (*pgx.Conn, error)

ConnectWithInstrumentation returns a pgx.Conn that has been instrumented for observability

func ConvertToWriteConstraintError

func ConvertToWriteConstraintError(livingTupleConstraints []string, err error) error

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

func IsCancellationError added in v1.26.0

func IsCancellationError(err error) bool

IsCancellationError determines if an error returned by pgx has been caused by context cancellation.

func IsConstraintFailureError added in v1.34.0

func IsConstraintFailureError(err error) bool

IsConstraintFailureError returns true if the error is a Postgres error indicating a constraint failure.

func IsSerializationError added in v1.26.0

func IsSerializationError(err error) bool

func NewPGXExecutor

func NewPGXExecutor(querier DBFuncQuerier) common.ExecuteQueryFunc

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

func ParseConfigWithInstrumentation added in v1.29.0

func ParseConfigWithInstrumentation(url string) (*pgx.ConnConfig, error)

ParseConfigWithInstrumentation returns a pgx.ConnConfig that has been instrumented for observability

func SleepOnErr added in v1.26.0

func SleepOnErr(ctx context.Context, err error, retries uint8)

SleepOnErr sleeps for a short period of time after an error has occurred.

Types

type ComposedTracer added in v1.24.0

type ComposedTracer struct {
	Tracers []pgx.QueryTracer
}

ComposedTracer allows adding multiple tracers to a pgx.ConnConfig

func (*ComposedTracer) TraceQueryEnd added in v1.24.0

func (m *ComposedTracer) TraceQueryEnd(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryEndData)

func (*ComposedTracer) TraceQueryStart added in v1.24.0

func (m *ComposedTracer) TraceQueryStart(ctx context.Context, conn *pgx.Conn, data pgx.TraceQueryStartData) context.Context

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