Documentation ¶
Overview ¶
Package sqlq deals with building of sql query.
Index ¶
- Constants
- type JoinConfig
- type Option
- func AND(opts ...Option) Option
- func All() Option
- func Columns(columns ...string) Option
- func Equal(field string, value interface{}) Option
- func GreaterOrEqual(field string, value interface{}) Option
- func GreaterThan(field string, value interface{}) Option
- func GroupBy(columns ...string) Option
- func Having(opts ...Option) Option
- func IN(field string, values ...string) Option
- func Join(structPtr interface{}, condition string, columns ...string) Option
- func LessOrEqual(field string, value interface{}) Option
- func LessThan(field string, value interface{}) Option
- func Like(field string, pattern string) Option
- func Limit(limit int) Option
- func NotEqual(field string, value interface{}) Option
- func OR(opts ...Option) Option
- func Offset(offset int) Option
- func Order(field string, orderBy string) Option
- func Raw(query string, args ...interface{}) Option
- type Query
Constants ¶
const ( ASC = "ASC" DESC = "DESC" )
order operators
const ( OpSelect = "select" OpInsert = "insert" OpUpdate = "update" OpDelete = "delete" )
these flags describe whether query option is allowed for a specific db operation.
const DefaultSelectLimit = 1000
DefaultSelectLimit sets the default limit for select if no limit specified.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JoinConfig ¶
JoinConfig describes join config.
type Option ¶
Option describes common function for building query.
func All ¶
func All() Option
All enforses quering all data (like where 1=1) used to prevent unintentional update or delete of all rows in table.
func Columns ¶
Columns specifies columns that needs to be fetched. By default all columns are fetched.
func GreaterOrEqual ¶
GreaterOrEqual adds where field >= value construction to query.
func GreaterThan ¶
GreaterThan adds where field > value construction to query.
func GroupBy ¶
GroupBy adds group by construction to query. Example: mw.GroupBy("user_id"), or mw.GroupBy("user_id", "price")
func Join ¶
Join adds join to query.
- define joined struct
- search for field with mw:"join" tag
- compare struct type, if same, add field address to fields slice
- when scan, check whether model row already exist, if yes, try to join rows
- TODO: how to join rows with multiple join case?????????????????????
- probably duplicate address to keep raw data in order to easy compare it
func LessOrEqual ¶
LessOrEqual adds where field <= value construction to query.
func Offset ¶
Offset adds limit offset to query. If multiple offsets specified, the last one will be set.