package mySql import "fmt" type Where struct { Formula string Values []interface{} } func NewWhere(formula string, values ...interface{}) *Where { return &Where{ Formula: formula, Values: values, } } func NewWheres(where ...*Where) []*Where { return where } func NewEqWhere(colName string, value interface{}) *Where { return &Where{ Formula: fmt.Sprintf("`%s` = ?", colName), Values: []interface{}{value}, } } func NewNeqWhere(colName string, value interface{}) *Where { return &Where{ Formula: fmt.Sprintf("`%s` <> ?", colName), Values: []interface{}{value}, } } func NewGtWhere(colName string, value interface{}) *Where { return &Where{ Formula: fmt.Sprintf("`%s` > ?", colName), Values: []interface{}{value}, } } func NewEgtWhere(colName string, value interface{}) *Where { return &Where{ Formula: fmt.Sprintf("`%s` >= ?", colName), Values: []interface{}{value}, } } func NewLtWhere(colName string, value interface{}) *Where { return &Where{ Formula: fmt.Sprintf("`%s` < ?", colName), Values: []interface{}{value}, } } func NewEltWhere(colName string, value interface{}) *Where { return &Where{ Formula: fmt.Sprintf("`%s` <= ?", colName), Values: []interface{}{value}, } } func NewNotLikeWhere(colName string, value interface{}) *Where { return &Where{ Formula: fmt.Sprintf("`%s` NOT LIKE ?", colName), Values: []interface{}{value}, } } func NewLikeWhere(colName string, value interface{}) *Where { return &Where{ Formula: fmt.Sprintf("`%s` LIKE ?", colName), Values: []interface{}{value}, } } func NewBetweenWhere(colName string, value1 interface{}, value2 interface{}) *Where { return &Where{ Formula: fmt.Sprintf("(`%s` BETWEEN ? AND ?)", colName), Values: []interface{}{value1, value2}, } } func NewNotBetweenWhere(colName string, value1 interface{}, value2 interface{}) *Where { return &Where{ Formula: fmt.Sprintf("(`%s` NOT BETWEEN ? AND ?)", colName), Values: []interface{}{value1, value2}, } } func NewInWhere(colName string, value interface{}) *Where { return &Where{ Formula: fmt.Sprintf("`%s` IN ?", colName), Values: []interface{}{value}, } } func NewNotInWhere(colName string, value interface{}) *Where { return &Where{ Formula: fmt.Sprintf("`%s` NOT IN ?", colName), Values: []interface{}{value}, } } func NewIsNullWhere(colName string) *Where { return &Where{ Formula: fmt.Sprintf("`%s` IS NULL", colName), Values: []interface{}{}, } } func NewIsNotNullWhere(colName string) *Where { return &Where{ Formula: fmt.Sprintf("`%s` IS NOT NULL ?", colName), Values: []interface{}{}, } }