Documentation ¶
Index ¶
- Variables
- func WithVars(vars ...interface{}) []interface{}
- type QueryOption
- type QueryOptionFn
- type QueryOptionFns
- type RowScanner
- type SQL
- func (s *SQL) Append(sub string, args ...interface{}) *SQL
- func (s SQL) CreateCount() (*SQL, error)
- func (s SQL) QueryAsBeans(db *sql.DB, result interface{}, optionFns ...QueryOptionFn) error
- func (s SQL) QueryAsMap(db *sql.DB, optionFns ...QueryOptionFn) (map[string]string, error)
- func (s SQL) QueryAsMaps(db *sql.DB, optionFns ...QueryOptionFn) ([]map[string]string, error)
- func (s SQL) QueryAsNumber(db *sql.DB) (int64, error)
- func (s SQL) QueryAsRow(db *sql.DB, optionFns ...QueryOptionFn) ([]string, error)
- func (s SQL) QueryAsRows(db *sql.DB, optionFns ...QueryOptionFn) ([][]string, error)
- func (s SQL) QueryAsString(db *sql.DB) (string, error)
- func (s SQL) QueryRaw(db *sql.DB, optionFns ...QueryOptionFn) error
- func (s SQL) Update(db *sql.DB) (int64, error)
- func (s *SQL) WithVars(vars ...interface{}) *SQL
- type ScanRowFn
Constants ¶
This section is empty.
Variables ¶
var ( TypeInt64 = reflect.TypeOf(int64(0)) TypeUint64 = reflect.TypeOf(uint64(0)) TypeFloat64 = reflect.TypeOf(float64(0)) )
var ErrConditionKind = errors.New("condition kind should be struct or its pointer")
ErrConditionKind tells that the condition kind should be struct or its pointer
var ErrNotSelect = errors.New("not a select query statement")
ErrNotSelect shows an error that the query is not a select statement.
Functions ¶
Types ¶
type QueryOption ¶
type QueryOption struct { MaxRows int TagNames []string Scanner RowScanner }
QueryOption defines the query options.
type QueryOptionFn ¶
type QueryOptionFn func(o *QueryOption)
QueryOptionFn define the prototype function to set QueryOption.
func WithMaxRows ¶
func WithMaxRows(maxRows int) QueryOptionFn
WithMaxRows set the max rows of QueryOption.
func WithOptions ¶
func WithOptions(v *QueryOption) QueryOptionFn
WithOptions apply the query option directly.
func WithRowScanner ¶
func WithRowScanner(v RowScanner) QueryOptionFn
WithRowScanner set row scanner for the query result.
func WithScanRow ¶
func WithScanRow(v ScanRowFn) QueryOptionFn
WithScanRow set row scanner for the query result.
func WithTagNames ¶
func WithTagNames(tagNames ...string) QueryOptionFn
WithTagNames set the tagNames for mapping struct fields to query columns.
type QueryOptionFns ¶
type QueryOptionFns []QueryOptionFn
QueryOptionFns is the slice of QueryOptionFn.
func (QueryOptionFns) Options ¶
func (q QueryOptionFns) Options() *QueryOption
type RowScanner ¶
type SQL ¶
type SQL struct { Query string Vars []interface{} }
SQL is a structure for query and vars.
func (SQL) CreateCount ¶
CreateCount creates a count query sql.
func (SQL) QueryAsBeans ¶
func (s SQL) QueryAsBeans(db *sql.DB, result interface{}, optionFns ...QueryOptionFn) error
QueryAsBeans query return with result.
func (SQL) QueryAsMap ¶
QueryAsMap query a single row as a map return.
func (SQL) QueryAsMaps ¶
QueryAsMaps query rows as map slice.
func (SQL) QueryAsNumber ¶
QueryAsNumber executes a query which only returns number like count(*) sql.
func (SQL) QueryAsRow ¶
QueryAsRow query a single row as a string slice return.
func (SQL) QueryAsRows ¶
QueryAsRows query rows as [][]string.
func (SQL) QueryAsString ¶
QueryAsNumber executes a query which only returns number like count(*) sql.
func (SQL) QueryRaw ¶
func (s SQL) QueryRaw(db *sql.DB, optionFns ...QueryOptionFn) error
QueryRaw query rows for customized row scanner.