middleware

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package middleware is used in pggen to add middleware to be executed surrounding the DB calls execution. The intent is to have the ability to add custom logging, metrics, tracing, side effects.

The DBConnWrapper struct is the main character of this package. It wraps a database connection, and implements the database connection interface itself. The thing it brings to the table is making it easy to inject your own interceptor routines for commen SQL operations.

In addition to allowing you to hook SQL operations, you can attach an ErrorConverter routine to the DBConnWrapper. This routine will be called by the generated code before any error is returned. This allows you to conveniantly translate pggen errors into the error format used in the rest of your application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BeginTxFunc

type BeginTxFunc func(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

type BeginTxMiddleware

type BeginTxMiddleware func(BeginTxFunc) BeginTxFunc

type DBConnWrapper

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

DBConnWrapper is a wrapper around DBConn that also contain the middlewares to apply when doing the DB calls

func NewDBConnWrapper

func NewDBConnWrapper(dbConn pggen.DBConn) *DBConnWrapper

NewDBConnWrapper wraps the DBConn in struct to which middlewares can be added

func (*DBConnWrapper) BeginTx

func (w *DBConnWrapper) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx applies the middleware if any and executes BeginTx on the wrapped DBConn

func (*DBConnWrapper) Close

func (w *DBConnWrapper) Close() error

func (*DBConnWrapper) Conn

func (w *DBConnWrapper) Conn(ctx context.Context) (*sql.Conn, error)

func (*DBConnWrapper) Driver

func (w *DBConnWrapper) Driver() driver.Driver

func (*DBConnWrapper) ErrorConverter

func (w *DBConnWrapper) ErrorConverter() func(error) error

ErrorConverter returns a function to be applied to all error values before they are returned from the generated client. It is meant to be called by the generated NewPGClient routine, and probably doesn't ever need to be called from user code.

func (*DBConnWrapper) ExecContext

func (w *DBConnWrapper) ExecContext(ctx context.Context, stmt string, args ...interface{}) (sql.Result, error)

ExecContext applies the middleware if any and executes ExecContext on the wrapped DBConn

func (*DBConnWrapper) PingContext

func (w *DBConnWrapper) PingContext(ctx context.Context) error

func (*DBConnWrapper) PrepareContext

func (w *DBConnWrapper) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

func (*DBConnWrapper) QueryContext

func (w *DBConnWrapper) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext applies the middleware if any and executes QueryContext on the wrapped DBConn

func (*DBConnWrapper) QueryRowContext

func (w *DBConnWrapper) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext applies the middleware if any and executes QueryRowContext on the wrapped DBConn

func (*DBConnWrapper) SetConnMaxLifetime

func (w *DBConnWrapper) SetConnMaxLifetime(d time.Duration)

func (*DBConnWrapper) SetMaxIdleConns

func (w *DBConnWrapper) SetMaxIdleConns(n int)

func (*DBConnWrapper) SetMaxOpenConns

func (w *DBConnWrapper) SetMaxOpenConns(n int)

func (*DBConnWrapper) Stats

func (w *DBConnWrapper) Stats() sql.DBStats

func (*DBConnWrapper) WithBeginTxMiddleware

func (w *DBConnWrapper) WithBeginTxMiddleware(beginTxMiddleware BeginTxMiddleware) *DBConnWrapper

WithWithBeginTxMiddleware adds the middleware for the BeginTx to the DBConnWrapper

func (*DBConnWrapper) WithErrorConverter

func (w *DBConnWrapper) WithErrorConverter(errorConverter func(error) error) *DBConnWrapper

WithErrorConverter adds an error converter function. A builder method.

func (*DBConnWrapper) WithExecMiddleware

func (w *DBConnWrapper) WithExecMiddleware(execMiddleware ExecMiddleware) *DBConnWrapper

WithExecMiddleware adds the middleware for the ExecContext to the DBConnWrapper

func (*DBConnWrapper) WithQueryMiddleware

func (w *DBConnWrapper) WithQueryMiddleware(queryMiddleware QueryMiddleware) *DBConnWrapper

WithQueryMiddleware adds the middleware for the QueryContext to the DBConnWrapper

func (*DBConnWrapper) WithQueryRowMiddleware

func (w *DBConnWrapper) WithQueryRowMiddleware(queryRowMiddleware QueryRowMiddleware) *DBConnWrapper

WithQueryRowMiddleware adds the middleware for the QueryRowContext to the DBConnWrapper

type ExecFunc

type ExecFunc func(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

type ExecMiddleware

type ExecMiddleware func(ExecFunc) ExecFunc

type QueryFunc

type QueryFunc func(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

type QueryMiddleware

type QueryMiddleware func(QueryFunc) QueryFunc

type QueryRowFunc

type QueryRowFunc func(ctx context.Context, query string, args ...interface{}) *sql.Row

type QueryRowMiddleware

type QueryRowMiddleware func(QueryRowFunc) QueryRowFunc

Jump to

Keyboard shortcuts

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