mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* add query builder to facilitate dynamic SQL construction * leverage query builder to refactor user store This is partially setup work for MM-13120, but merged to master to avoid further conflicts. * fix unrelated unit test breakage * documentation tweaks * Apply suggestions from code review Co-Authored-By: lieut-data <jesse.hallam@gmail.com> * prefer comma separated case options to fallthrough * vendor github.com/Masterminds/squirrel and deps * switch to using github.com/Masterminds/squirrel * rm querybuilder
62 lines
2.0 KiB
Go
62 lines
2.0 KiB
Go
// +build go1.8
|
|
|
|
package squirrel
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"errors"
|
|
)
|
|
|
|
// NoContextSupport is returned if a db doesn't support Context.
|
|
var NoContextSupport = errors.New("DB does not support Context")
|
|
|
|
// ExecerContext is the interface that wraps the ExecContext method.
|
|
//
|
|
// Exec executes the given query as implemented by database/sql.ExecContext.
|
|
type ExecerContext interface {
|
|
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
|
|
}
|
|
|
|
// QueryerContext is the interface that wraps the QueryContext method.
|
|
//
|
|
// QueryContext executes the given query as implemented by database/sql.QueryContext.
|
|
type QueryerContext interface {
|
|
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
|
|
}
|
|
|
|
// QueryRowerContext is the interface that wraps the QueryRowContext method.
|
|
//
|
|
// QueryRowContext executes the given query as implemented by database/sql.QueryRowContext.
|
|
type QueryRowerContext interface {
|
|
QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner
|
|
}
|
|
|
|
func (r *stdsqlRunner) QueryRowContext(ctx context.Context, query string, args ...interface{}) RowScanner {
|
|
return r.stdsql.QueryRowContext(ctx, query, args...)
|
|
}
|
|
|
|
// ExecContextWith ExecContexts the SQL returned by s with db.
|
|
func ExecContextWith(ctx context.Context, db ExecerContext, s Sqlizer) (res sql.Result, err error) {
|
|
query, args, err := s.ToSql()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return db.ExecContext(ctx, query, args...)
|
|
}
|
|
|
|
// QueryContextWith QueryContexts the SQL returned by s with db.
|
|
func QueryContextWith(ctx context.Context, db QueryerContext, s Sqlizer) (rows *sql.Rows, err error) {
|
|
query, args, err := s.ToSql()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return db.QueryContext(ctx, query, args...)
|
|
}
|
|
|
|
// QueryRowContextWith QueryRowContexts the SQL returned by s with db.
|
|
func QueryRowContextWith(ctx context.Context, db QueryRowerContext, s Sqlizer) RowScanner {
|
|
query, args, err := s.ToSql()
|
|
return &Row{RowScanner: db.QueryRowContext(ctx, query, args...), err: err}
|
|
}
|