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 ¶
- type BeginTxFunc
- type BeginTxMiddleware
- type DBConnWrapper
- func (w *DBConnWrapper) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
- func (w *DBConnWrapper) Close() error
- func (w *DBConnWrapper) Conn(ctx context.Context) (*sql.Conn, error)
- func (w *DBConnWrapper) Driver() driver.Driver
- func (w *DBConnWrapper) ErrorConverter() func(error) error
- func (w *DBConnWrapper) ExecContext(ctx context.Context, stmt string, args ...interface{}) (sql.Result, error)
- func (w *DBConnWrapper) PingContext(ctx context.Context) error
- func (w *DBConnWrapper) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (w *DBConnWrapper) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (w *DBConnWrapper) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (w *DBConnWrapper) SetConnMaxLifetime(d time.Duration)
- func (w *DBConnWrapper) SetMaxIdleConns(n int)
- func (w *DBConnWrapper) SetMaxOpenConns(n int)
- func (w *DBConnWrapper) Stats() sql.DBStats
- func (w *DBConnWrapper) WithBeginTxMiddleware(beginTxMiddleware BeginTxMiddleware) *DBConnWrapper
- func (w *DBConnWrapper) WithErrorConverter(errorConverter func(error) error) *DBConnWrapper
- func (w *DBConnWrapper) WithExecMiddleware(execMiddleware ExecMiddleware) *DBConnWrapper
- func (w *DBConnWrapper) WithQueryMiddleware(queryMiddleware QueryMiddleware) *DBConnWrapper
- func (w *DBConnWrapper) WithQueryRowMiddleware(queryRowMiddleware QueryRowMiddleware) *DBConnWrapper
- type ExecFunc
- type ExecMiddleware
- type QueryFunc
- type QueryMiddleware
- type QueryRowFunc
- type QueryRowMiddleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 ¶
BeginTx applies the middleware if any and executes BeginTx on the wrapped DBConn
func (*DBConnWrapper) Close ¶
func (w *DBConnWrapper) Close() 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 (*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 ExecMiddleware ¶
type QueryMiddleware ¶
type QueryRowFunc ¶
type QueryRowMiddleware ¶
type QueryRowMiddleware func(QueryRowFunc) QueryRowFunc