Documentation ¶
Overview ¶
Package dbutil basically provides DbContext to simplify DB interaction
Index ¶
- Variables
- type DatasetFlag
- type DbAccessor
- type DbConnectionHelper
- type DbContext
- func (dbContext *DbContext) CheckPGXBatchErr(br pgx.BatchResults) error
- func (dbContext *DbContext) Close() error
- func (dbContext *DbContext) Commit(restartTx bool) error
- func (dbContext *DbContext) Execute(query string, args ...interface{}) error
- func (dbContext *DbContext) GetPGXConn() (*pgx.Conn, error)
- func (dbContext *DbContext) LastError() error
- func (dbContext *DbContext) Query(query string, args ...interface{}) (RowsAccessor, error)
- func (dbContext *DbContext) QueryRow(query string, args ...interface{}) (*sql.Row, error)
- func (dbContext *DbContext) RegisterErrorHandler(errorHandler func(err error))
- func (dbContext *DbContext) ResetError()
- func (dbContext *DbContext) Rollback(restartTx bool) error
- func (dbContext *DbContext) ScanQueryRow(supressErrNoRows bool, query Query, destination []interface{}) error
- func (dbContext *DbContext) SetLastError(err error)
- type Query
- type RowsAccessor
Constants ¶
This section is empty.
Variables ¶
var SKIP_ERROR error = fmt.Errorf("Skipping due to previous error")
Functions ¶
This section is empty.
Types ¶
type DbAccessor ¶
type DbAccessor interface { RegisterErrorHandler(errorHandler func(err error)) QueryRow(query string, args ...interface{}) (*sql.Row, error) ScanQueryRow(supressErrNoRows bool, query Query, destination []interface{}) error Query(query string, args ...interface{}) (RowsAccessor, error) Execute(query string, args ...interface{}) error Commit(restartTx bool) error Rollback(restartTx bool) error Close() error GetPGXConn() (*pgx.Conn, error) CheckPGXBatchErr(br pgx.BatchResults) error LastError() error SetLastError(err error) ResetError() }
type DbConnectionHelper ¶
type DbConnectionHelper struct { DbConnectionURL string MaxOpenConns int MaxIdleConns int ConnMaxLifeTime int // contains filtered or unexported fields }
func (*DbConnectionHelper) CloseContexts ¶
func (helper *DbConnectionHelper) CloseContexts()
CloseContexts closes all open db connections
func (*DbConnectionHelper) GetDbContext ¶
func (helper *DbConnectionHelper) GetDbContext(ctx *context.Context, useTransaction bool) (dbContext *DbContext)
GetDbContext returns a context in which queries (including inserts, deletes) can be executed. ctx allows optional context cancellation if not nil DbContext.Err and any transaction are resetted
type DbContext ¶
type DbContext struct {
// contains filtered or unexported fields
}
func (*DbContext) CheckPGXBatchErr ¶
CheckPGXErr applies the first error of a PGX batch to dbContext.Err, and logs all of them
func (*DbContext) Close ¶
Close commits the transaction. In case of an error the transaction is rolled back. dbContext.Err is set to nil
func (*DbContext) Execute ¶
Execute runs given query with given substitution parameters as for $1 etc. The operation becomes a no-op if there is a previous error in DbContext.err
func (*DbContext) GetPGXConn ¶
func (*DbContext) Query ¶
func (dbContext *DbContext) Query(query string, args ...interface{}) (RowsAccessor, error)
Query returns all rows for given query with given substituion paramaters. The operation becomes a no-op if there is a previous error in DbContext.err.
func (*DbContext) QueryRow ¶
QueryRow returns at most one row for given query with given substituion paramaters. The operation becomes a no-op if there is a previous error in DbContext.err.
func (*DbContext) RegisterErrorHandler ¶
RegisterErrorHandler registers function as error handler to call in case DbContext.Err is set. Any previous handler is overwritten.
func (*DbContext) ResetError ¶
func (dbContext *DbContext) ResetError()
func (*DbContext) ScanQueryRow ¶
func (dbContext *DbContext) ScanQueryRow(supressErrNoRows bool, query Query, destination []interface{}) error
ScanQueryRow executes the given query with optional args and writes colums of the first row (if present) to given destination parameters The operation becomes a no-op if there is a previous error in DbContext.err. If supressErrNoRows and error occurrs, destination value are reset to ""
func (*DbContext) SetLastError ¶
type Query ¶
type Query struct { Query string Args []interface{} }
Query allows to pass parametrized query an single function parameter