Documentation ¶
Overview ¶
Package goquutil provides auxiliary routines for working with goqu query builder. Warning: until this notice is removed, current state is "beta", i.e. it is being tested in selected projects for errors and completeness. This also means that APIs may change without any guarantees for backward compatibility.
Index ¶
- Variables
- func BuildSQLAndExec(q Querier, sqlExpression exp.SQLExpression) (sql.Result, error)
- func BuildSQLAndQuery(q Querier, sqlExpression exp.SQLExpression) (*sql.Rows, error)
- func BuildSQLAndQueryRow(q Querier, sqlExpression exp.SQLExpression) (*sql.Row, error)
- func BuildSQLAndQueryScalar(q Querier, sqlExpression exp.SQLExpression, scalar interface{}) error
- func JSONDecoder(i interface{}) sql.Scanner
- func JSONEncoder(i interface{}) driver.Valuer
- func QueryAndScanStruct(q Querier, query *goqu.SelectDataset, composite interface{}) error
- func QueryAndScanStructs(q Querier, query *goqu.SelectDataset, composite interface{}) error
- func QueryAndScanValues(q Querier, query *goqu.SelectDataset, result interface{}) error
- func ScanEachRow(rows *sql.Rows, scanRow func(s Scanner) error) (rowsProcessed int, err error)
- type ContextProvider
- type DB
- type NullTime
- type PostQueryFuncT
- type PreQueryFuncT
- type Querier
- type QueryDurationObserverFunc
- type SQLBuilderSettings
- type Scanner
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound indicates that something was not found in db
var IsInsideTest bool
IsInsideTest when set to true enables some checks that are skipped for production code
Functions ¶
func BuildSQLAndExec ¶
BuildSQLAndExec is a function for running DML not returning any data like UPDATE, DELETE, INSERT
func BuildSQLAndQuery ¶
BuildSQLAndQuery is a function for running SELECT statements returning many rows
func BuildSQLAndQueryRow ¶
BuildSQLAndQueryRow is a function for running SELECT statements returning single row
func BuildSQLAndQueryScalar ¶
func BuildSQLAndQueryScalar(q Querier, sqlExpression exp.SQLExpression, scalar interface{}) error
BuildSQLAndQueryScalar is a function for running SELECT statements returning single scalar value
func JSONDecoder ¶
JSONDecoder is convenience function for reading JSON values from db
func JSONEncoder ¶
JSONEncoder is convenience function for writing JSON values to db
func QueryAndScanStruct ¶
QueryAndScanStruct scans results into composite struct
func QueryAndScanStructs ¶
QueryAndScanStructs scans results into structs (using common goqu rules about tags) it allows scanning from queries that contain JOINs between tables other than INNER JOIN
func QueryAndScanValues ¶
QueryAndScanValues runs SELECT and scans its result into values list, result is a pointer to slice of values: SELECT attr FROM t WHERE t.id > 123
Types ¶
type ContextProvider ¶
ContextProvider is an interface that defines a method for obtaining a context.Context. Implementing types should return the context.Context representing the execution context of the operation or task.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a wrapper for goqu.Database
func (*DB) WithLogging ¶
func (d *DB) WithLogging(logger golibslog.FieldLogger, loggingCtx string, loggingTimeThresholdBeginTx time.Duration) *DB
WithLogging enables logging of time consumed on openning/getting DB connection from pool
type NullTime ¶
NullTime is suitable in case of different functions working with time Note! It's suitable for in case you use goqu.MAX(date_column) on SQLite. It's not required on MySQL. MySQL can work with sql.NullTime sql.NullTime is not suitable in such case because on SQLite driver cannot detect type of MAX(date_column) expression as timestamp and handle it as a text, the problem can be in function (rc *SQLiteRows) declTypes() []string at github.com/mattn/go-sqlite3/sqlite3.go
func NullTimeFrom ¶
NullTimeFrom creates valid NullTime from time.Time
type PostQueryFuncT ¶
type PostQueryFuncT func(ctx context.Context, startedAt time.Time, err error, query string, args ...interface{})
PostQueryFuncT is type for post query hook function
var PostQueryHook PostQueryFuncT
PostQueryHook will be executed after actual query execution
type PreQueryFuncT ¶
PreQueryFuncT is type for pre query hook function
var PreQueryHook PreQueryFuncT
PreQueryHook will be executed before actual query execution
type Querier ¶
type Querier interface { QueryRow(query string, args ...interface{}) *sql.Row Query(query string, args ...interface{}) (*sql.Rows, error) Exec(query string, args ...interface{}) (sql.Result, error) }
Querier is an interface to abstract details of db implementation
type QueryDurationObserverFunc ¶
type QueryDurationObserverFunc func(preparedQueryString string, ctx context.Context, startTime time.Time, err error)
QueryDurationObserverFunc is a function type to observe query related stats
var ObserveSQLQueryDuration QueryDurationObserverFunc
ObserveSQLQueryDuration is an actual instance of QueryDurationObserverFunc that is used
type SQLBuilderSettings ¶
type SQLBuilderSettings struct {
Dialect goqu.DialectWrapper
}
SQLBuilderSettings is sql builder settings representation