Documentation ¶
Index ¶
- Variables
- func BuildDelete(table string, where map[string]interface{}) (string, []interface{}, error)
- func BuildInsert(table string, data []map[string]interface{}) (string, []interface{}, error)
- func BuildInsertIgnore(table string, data []map[string]interface{}) (string, []interface{}, error)
- func BuildInsertOnDuplicate(table string, data []map[string]interface{}, update map[string]interface{}) (string, []interface{}, error)
- func BuildReplaceInsert(table string, data []map[string]interface{}) (string, []interface{}, error)
- func BuildSelect(table string, where map[string]interface{}, selectField []string) (cond string, vals []interface{}, err error)
- func BuildUpdate(table string, where map[string]interface{}, update map[string]interface{}) (string, []interface{}, error)
- func NamedQuery(sql string, data map[string]interface{}) (string, []interface{}, error)
- func OmitEmpty(where map[string]interface{}, omitKey []string) map[string]interface{}
- type AggregateSymbleBuilder
- type Between
- type Comparable
- func Custom(query string, args ...interface{}) Comparable
- func JsonArrayAppend(field string, pathAndValuePair ...interface{}) Comparable
- func JsonArrayInsert(field string, pathAndValuePair ...interface{}) Comparable
- func JsonContains(fullJsonPath string, jsonLike interface{}) Comparable
- func JsonRemove(field string, path ...string) Comparable
- func JsonSet(field string, pathAndValuePair ...interface{}) Comparable
- type Eq
- type Gt
- type Gte
- type In
- type IsZeroer
- type Like
- type Lt
- type Lte
- type Ne
- type NestWhere
- type NotBetween
- type NotIn
- type NotLike
- type NullType
- type OrWhere
- type Raw
- type ResultResolver
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnsupportedOperator reports there's unsupported operators in where-condition ErrUnsupportedOperator = errors.New("[builder] unsupported operator") )
var IsZeroType = reflect.TypeOf((*IsZeroer)(nil)).Elem()
Functions ¶
func BuildDelete ¶
BuildDelete work as its name says
func BuildInsert ¶
BuildInsert work as its name says
func BuildInsertIgnore ¶ added in v1.1.0
BuildInsertIgnore work as its name says
func BuildInsertOnDuplicate ¶ added in v1.5.0
func BuildInsertOnDuplicate(table string, data []map[string]interface{}, update map[string]interface{}) (string, []interface{}, error)
BuildInsertOnDuplicateKey builds an INSERT ... ON DUPLICATE KEY UPDATE clause.
func BuildReplaceInsert ¶ added in v1.1.0
BuildReplaceInsert work as its name says
func BuildSelect ¶
func BuildSelect(table string, where map[string]interface{}, selectField []string) (cond string, vals []interface{}, err error)
BuildSelect work as its name says. supported operators including: =,in,>,>=,<,<=,<>,!=. key without operator will be regarded as =. special key begin with _: _orderby,_groupby,_limit,_having. the value of _limit must be a slice whose type should be []uint and must contain two uints(ie: []uint{0, 100}). the value of _having must be a map just like where but only support =,in,>,>=,<,<=,<>,!= for more examples,see README.md or open a issue.
func BuildUpdate ¶
func BuildUpdate(table string, where map[string]interface{}, update map[string]interface{}) (string, []interface{}, error)
BuildUpdate work as its name says
func NamedQuery ¶
NamedQuery is used for expressing complex query
Types ¶
type AggregateSymbleBuilder ¶
type AggregateSymbleBuilder interface {
Symble() string
}
AggregateSymbleBuilder need to be implemented so that executor can get what should be put into `select Symble() from xxx where yyy`
func AggregateCount ¶
func AggregateCount(col string) AggregateSymbleBuilder
AggregateCount count(col)
type Comparable ¶
type Comparable interface {
Build() ([]string, []interface{})
}
Comparable requires type implements the Build method
func Custom ¶ added in v1.9.0
func Custom(query string, args ...interface{}) Comparable
func JsonArrayAppend ¶ added in v1.9.0
func JsonArrayAppend(field string, pathAndValuePair ...interface{}) Comparable
JsonArrayAppend gen JsonObj and call MySQL JSON_ARRAY_APPEND function; usage update := map[string]interface{}{"_custom_xxx": builder.JsonArrayAppend(field, "$", 1, "$[last]", []string{"2","3"}}
func JsonArrayInsert ¶ added in v1.9.0
func JsonArrayInsert(field string, pathAndValuePair ...interface{}) Comparable
JsonArrayInsert gen JsonObj and call MySQL JSON_ARRAY_INSERT function; insert at index usage update := map[string]interface{}{"_custom_xxx": builder.JsonArrayInsert(field, "$[0]", 1, "$[0]", []string{"2","3"}}
func JsonContains ¶ added in v1.9.0
func JsonContains(fullJsonPath string, jsonLike interface{}) Comparable
JsonContains aim to check target json contains all items in given obj;if check certain value just use direct where := map[string]interface{}{"your_json_field.'$.path_to_key' =": val}
notice: fullJsonPath should hard code, never from user input; jsonLike only support json element like array,map,string,number etc., struct input will result panic!!!
usage where := map[string]interface{}{"_custom_xxx": builder.JsonContains("my_json->'$.my_data.list'", 7)}
usage where := map[string]interface{}{"_custom_xxx": builder.JsonContains("my_json->'$'", []int{1,2})}
usage where := map[string]interface{}{"_custom_xxx": builder.JsonContains("my_json->'$.user_info'", map[string]any{"name": "", "age": 18})}
func JsonRemove ¶ added in v1.9.0
func JsonRemove(field string, path ...string) Comparable
JsonRemove call MySQL JSON_REMOVE function; remove element from Array or Map path removed in order, prev remove affect the later operation, maybe the array shrink
remove last array element; update := map[string]interface{}{"_custom_xxx":builder.JsonRemove(field,'$.list[last]')} remove element; update := map[string]interface{}{"_custom_xxx":builder.JsonRemove(field,'$.key0')}
func JsonSet ¶ added in v1.9.0
func JsonSet(field string, pathAndValuePair ...interface{}) Comparable
JsonSet aim to simply set/update json field operation;
notice: jsonPath should hard code, never from user input;
usage update := map[string]interface{}{"_custom_xxx": builder.JsonSet(field, "$.code", 1, "$.user_info", map[string]any{"name": "", "age": 18})}
type NestWhere ¶ added in v1.4.0
type NestWhere []Comparable
type NotBetween ¶ added in v1.2.0
type NotBetween map[string][]interface{}
func (NotBetween) Build ¶ added in v1.2.0
func (nbt NotBetween) Build() ([]string, []interface{})
type NullType ¶
type NullType byte
NullType is the NULL type in mysql
const ( // IsNull the same as `is null` IsNull NullType // IsNotNull the same as `is not null` IsNotNull )
type OrWhere ¶ added in v1.4.0
type OrWhere []Comparable
type ResultResolver ¶
ResultResolver is a helper for retrieving data caller should know the type and call the responding method
func AggregateQuery ¶
func AggregateQuery(ctx context.Context, db *sql.DB, table string, where map[string]interface{}, aggregate AggregateSymbleBuilder) (ResultResolver, error)
AggregateQuery is a helper function to execute the aggregate query and return the result