mirror of
https://github.com/tangpanqing/aorm.git
synced 2025-10-26 17:20:33 +08:00
update
This commit is contained in:
@@ -17,10 +17,11 @@ type FieldInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WhereItem struct {
|
type WhereItem struct {
|
||||||
Prefix string
|
FuncName string
|
||||||
Field interface{}
|
Prefix string
|
||||||
Opt string
|
Field interface{}
|
||||||
Val interface{}
|
Opt string
|
||||||
|
Val interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type SelectItem struct {
|
type SelectItem struct {
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const Count = "COUNT"
|
||||||
|
|
||||||
const Desc = "DESC"
|
const Desc = "DESC"
|
||||||
const Asc = "ASC"
|
const Asc = "ASC"
|
||||||
|
|
||||||
@@ -49,7 +51,7 @@ type Builder struct {
|
|||||||
tableName string
|
tableName string
|
||||||
selectList []SelectItem
|
selectList []SelectItem
|
||||||
selectExpList []*SelectItem
|
selectExpList []*SelectItem
|
||||||
groupList []string
|
groupList []interface{}
|
||||||
whereList []WhereItem
|
whereList []WhereItem
|
||||||
joinList []JoinItem
|
joinList []JoinItem
|
||||||
havingList []WhereItem
|
havingList []WhereItem
|
||||||
@@ -320,8 +322,8 @@ func (ex *Builder) GetSqlAndParams() (string, []interface{}) {
|
|||||||
fieldStr, paramList := ex.handleField(paramList)
|
fieldStr, paramList := ex.handleField(paramList)
|
||||||
whereStr, paramList := ex.handleWhere(paramList)
|
whereStr, paramList := ex.handleWhere(paramList)
|
||||||
joinStr, paramList := ex.handleJoin(paramList)
|
joinStr, paramList := ex.handleJoin(paramList)
|
||||||
groupStr := handleGroup(ex.groupList)
|
groupStr, paramList := ex.handleGroup(paramList)
|
||||||
havingStr, paramList := ex.handleHaving(ex.havingList, paramList)
|
havingStr, paramList := ex.handleHaving(paramList)
|
||||||
orderStr, paramList := ex.handleOrder(paramList)
|
orderStr, paramList := ex.handleOrder(paramList)
|
||||||
limitStr, paramList := ex.handleLimit(ex.offset, ex.pageSize, paramList)
|
limitStr, paramList := ex.handleLimit(ex.offset, ex.pageSize, paramList)
|
||||||
lockStr := handleLockForUpdate(ex.isLockForUpdate)
|
lockStr := handleLockForUpdate(ex.isLockForUpdate)
|
||||||
@@ -566,7 +568,7 @@ func (b *Builder) Table(table interface{}, alias ...string) *Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GroupBy 链式操作,以某字段进行分组
|
// GroupBy 链式操作,以某字段进行分组
|
||||||
func (ex *Builder) GroupBy(fieldName string) *Builder {
|
func (ex *Builder) GroupBy(fieldName interface{}) *Builder {
|
||||||
ex.groupList = append(ex.groupList, fieldName)
|
ex.groupList = append(ex.groupList, fieldName)
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
@@ -606,15 +608,17 @@ func (ex *Builder) LockForUpdate(isLockForUpdate bool) *Builder {
|
|||||||
func (ex *Builder) whereAndHaving(where []WhereItem, paramList []any) ([]string, []any) {
|
func (ex *Builder) whereAndHaving(where []WhereItem, paramList []any) ([]string, []any) {
|
||||||
var whereList []string
|
var whereList []string
|
||||||
for i := 0; i < len(where); i++ {
|
for i := 0; i < len(where); i++ {
|
||||||
prefix := where[i].Prefix
|
allFieldName := where[i].Prefix + "." + getFieldName(where[i].Field)
|
||||||
fieldName := getFieldName(where[i].Field)
|
if where[i].FuncName != "" {
|
||||||
|
allFieldName = where[i].FuncName + "(" + allFieldName + ")"
|
||||||
|
}
|
||||||
|
|
||||||
if "**builder.Builder" == reflect.TypeOf(where[i].Val).String() {
|
if "**builder.Builder" == reflect.TypeOf(where[i].Val).String() {
|
||||||
executor := *(**Builder)(unsafe.Pointer(reflect.ValueOf(where[i].Val).Pointer()))
|
executor := *(**Builder)(unsafe.Pointer(reflect.ValueOf(where[i].Val).Pointer()))
|
||||||
subSql, subParams := executor.GetSqlAndParams()
|
subSql, subParams := executor.GetSqlAndParams()
|
||||||
|
|
||||||
if where[i].Opt != Raw {
|
if where[i].Opt != Raw {
|
||||||
whereList = append(whereList, prefix+"."+fieldName+" "+where[i].Opt+" "+"("+subSql+")")
|
whereList = append(whereList, allFieldName+" "+where[i].Opt+" "+"("+subSql+")")
|
||||||
paramList = append(paramList, subParams...)
|
paramList = append(paramList, subParams...)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -622,15 +626,15 @@ func (ex *Builder) whereAndHaving(where []WhereItem, paramList []any) ([]string,
|
|||||||
} else {
|
} else {
|
||||||
if where[i].Opt == Eq || where[i].Opt == Ne || where[i].Opt == Gt || where[i].Opt == Ge || where[i].Opt == Lt || where[i].Opt == Le {
|
if where[i].Opt == Eq || where[i].Opt == Ne || where[i].Opt == Gt || where[i].Opt == Ge || where[i].Opt == Lt || where[i].Opt == Le {
|
||||||
if ex.driverName == model.Sqlite3 {
|
if ex.driverName == model.Sqlite3 {
|
||||||
whereList = append(whereList, prefix+"."+fieldName+" "+where[i].Opt+" "+"?")
|
whereList = append(whereList, allFieldName+" "+where[i].Opt+" "+"?")
|
||||||
} else {
|
} else {
|
||||||
switch where[i].Val.(type) {
|
switch where[i].Val.(type) {
|
||||||
case float32:
|
case float32:
|
||||||
whereList = append(whereList, ex.getConcatForFloat(prefix+"."+fieldName, "''")+" "+where[i].Opt+" "+"?")
|
whereList = append(whereList, ex.getConcatForFloat(allFieldName, "''")+" "+where[i].Opt+" "+"?")
|
||||||
case float64:
|
case float64:
|
||||||
whereList = append(whereList, ex.getConcatForFloat(prefix+"."+fieldName, "''")+" "+where[i].Opt+" "+"?")
|
whereList = append(whereList, ex.getConcatForFloat(allFieldName, "''")+" "+where[i].Opt+" "+"?")
|
||||||
default:
|
default:
|
||||||
whereList = append(whereList, prefix+"."+fieldName+" "+where[i].Opt+" "+"?")
|
whereList = append(whereList, allFieldName+" "+where[i].Opt+" "+"?")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -639,7 +643,7 @@ func (ex *Builder) whereAndHaving(where []WhereItem, paramList []any) ([]string,
|
|||||||
|
|
||||||
if where[i].Opt == Between || where[i].Opt == NotBetween {
|
if where[i].Opt == Between || where[i].Opt == NotBetween {
|
||||||
values := toAnyArr(where[i].Val)
|
values := toAnyArr(where[i].Val)
|
||||||
whereList = append(whereList, prefix+"."+fieldName+" "+where[i].Opt+" "+"(?) AND (?)")
|
whereList = append(whereList, allFieldName+" "+where[i].Opt+" "+"(?) AND (?)")
|
||||||
paramList = append(paramList, values...)
|
paramList = append(paramList, values...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -657,7 +661,7 @@ func (ex *Builder) whereAndHaving(where []WhereItem, paramList []any) ([]string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
whereList = append(whereList, prefix+"."+fieldName+" "+where[i].Opt+" "+ex.getConcatForLike(valueStr...))
|
whereList = append(whereList, allFieldName+" "+where[i].Opt+" "+ex.getConcatForLike(valueStr...))
|
||||||
}
|
}
|
||||||
|
|
||||||
if where[i].Opt == In || where[i].Opt == NotIn {
|
if where[i].Opt == In || where[i].Opt == NotIn {
|
||||||
@@ -667,12 +671,12 @@ func (ex *Builder) whereAndHaving(where []WhereItem, paramList []any) ([]string,
|
|||||||
placeholder = append(placeholder, "?")
|
placeholder = append(placeholder, "?")
|
||||||
}
|
}
|
||||||
|
|
||||||
whereList = append(whereList, prefix+"."+fieldName+" "+where[i].Opt+" "+"("+strings.Join(placeholder, ",")+")")
|
whereList = append(whereList, allFieldName+" "+where[i].Opt+" "+"("+strings.Join(placeholder, ",")+")")
|
||||||
paramList = append(paramList, values...)
|
paramList = append(paramList, values...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if where[i].Opt == Raw {
|
if where[i].Opt == Raw {
|
||||||
whereList = append(whereList, prefix+"."+fieldName+fmt.Sprintf("%v", where[i].Val))
|
whereList = append(whereList, allFieldName+fmt.Sprintf("%v", where[i].Val))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ func (ex *Builder) handleWhere(paramList []any) (string, []any) {
|
|||||||
return "", paramList
|
return "", paramList
|
||||||
}
|
}
|
||||||
|
|
||||||
whereList, paramList := ex.whereAndHaving(ex.whereList, paramList)
|
strList, paramList := ex.whereAndHaving(ex.whereList, paramList)
|
||||||
|
|
||||||
return " WHERE " + strings.Join(whereList, " AND "), paramList
|
return " WHERE " + strings.Join(strList, " AND "), paramList
|
||||||
}
|
}
|
||||||
|
|
||||||
//拼接SQL,更新信息
|
//拼接SQL,更新信息
|
||||||
@@ -110,23 +110,28 @@ func (b *Builder) handleJoin(paramList []interface{}) (string, []interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//拼接SQL,结果分组
|
//拼接SQL,结果分组
|
||||||
func handleGroup(groupList []string) string {
|
func (ex *Builder) handleGroup(paramList []any) (string, []any) {
|
||||||
if len(groupList) == 0 {
|
if len(ex.groupList) == 0 {
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return " GROUP BY " + strings.Join(groupList, ",")
|
|
||||||
}
|
|
||||||
|
|
||||||
//拼接SQL,结果筛选
|
|
||||||
func (ex *Builder) handleHaving(having []WhereItem, paramList []any) (string, []any) {
|
|
||||||
if len(having) == 0 {
|
|
||||||
return "", paramList
|
return "", paramList
|
||||||
}
|
}
|
||||||
|
|
||||||
whereList, paramList := ex.whereAndHaving(having, paramList)
|
var groupList []string
|
||||||
|
for i := 0; i < len(ex.groupList); i++ {
|
||||||
|
groupList = append(groupList, getFieldName(ex.groupList[i]))
|
||||||
|
}
|
||||||
|
|
||||||
return " Having " + strings.Join(whereList, " AND "), paramList
|
return " GROUP BY " + strings.Join(groupList, ","), paramList
|
||||||
|
}
|
||||||
|
|
||||||
|
//拼接SQL,结果筛选
|
||||||
|
func (ex *Builder) handleHaving(paramList []any) (string, []any) {
|
||||||
|
if len(ex.havingList) == 0 {
|
||||||
|
return "", paramList
|
||||||
|
}
|
||||||
|
|
||||||
|
strList, paramList := ex.whereAndHaving(ex.havingList, paramList)
|
||||||
|
|
||||||
|
return " Having " + strings.Join(strList, " AND "), paramList
|
||||||
}
|
}
|
||||||
|
|
||||||
//拼接SQL,结果排序
|
//拼接SQL,结果排序
|
||||||
|
|||||||
@@ -33,119 +33,145 @@ func (ex *Builder) HavingArr(havingList []WhereItem) *Builder {
|
|||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingEq(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingEq(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: Eq,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: Eq,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingNe(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingNe(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: Ne,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: Ne,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingGt(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingGt(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: Gt,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: Gt,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingGe(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingGe(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: Ge,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: Ge,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingLt(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingLt(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: Lt,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: Lt,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingLe(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingLe(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: Le,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: Le,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingIn(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingIn(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: In,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: In,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingNotIn(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingNotIn(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: NotIn,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: NotIn,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingBetween(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingBetween(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: Between,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: Between,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingNotBetween(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingNotBetween(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: NotBetween,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: NotBetween,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingLike(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingLike(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: Like,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: Like,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingNotLike(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingNotLike(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: NotLike,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: NotLike,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ex *Builder) HavingRaw(field string, val interface{}) *Builder {
|
func (ex *Builder) HavingRaw(funcName string, field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
ex.havingList = append(ex.havingList, WhereItem{
|
ex.havingList = append(ex.havingList, WhereItem{
|
||||||
Field: field,
|
FuncName: funcName,
|
||||||
Opt: Raw,
|
Prefix: getPrefixByField(field, prefix...),
|
||||||
Val: val,
|
Field: field,
|
||||||
|
Opt: Raw,
|
||||||
|
Val: val,
|
||||||
})
|
})
|
||||||
return ex
|
return ex
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,66 +34,66 @@ func (b *Builder) WhereArr(whereList []WhereItem) *Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereEq(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereEq(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, Eq, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, Eq, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereNe(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereNe(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, Ne, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, Ne, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereGt(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereGt(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, Gt, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, Gt, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereGe(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereGe(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, Ge, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, Ge, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereLt(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereLt(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, Lt, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, Lt, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereLe(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereLe(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, Le, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, Le, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereIn(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereIn(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, In, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, In, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereNotIn(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereNotIn(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, NotIn, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, NotIn, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereBetween(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereBetween(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, Between, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, Between, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereNotBetween(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereNotBetween(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, NotBetween, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, NotBetween, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereLike(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereLike(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, Like, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, Like, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereNotLike(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereNotLike(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, NotLike, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, NotLike, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WhereRaw(field interface{}, val interface{}, prefix ...string) *Builder {
|
func (b *Builder) WhereRaw(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||||
b.whereList = append(b.whereList, WhereItem{getPrefixByField(field, prefix...), field, Raw, val})
|
b.whereList = append(b.whereList, WhereItem{"", getPrefixByField(field, prefix...), field, Raw, val})
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"github.com/tangpanqing/aorm"
|
"github.com/tangpanqing/aorm"
|
||||||
"github.com/tangpanqing/aorm/builder"
|
"github.com/tangpanqing/aorm/builder"
|
||||||
|
"github.com/tangpanqing/aorm/model"
|
||||||
"github.com/tangpanqing/aorm/null"
|
"github.com/tangpanqing/aorm/null"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -60,10 +61,12 @@ type PersonWithArticleCount struct {
|
|||||||
var person = Person{}
|
var person = Person{}
|
||||||
var article = Article{}
|
var article = Article{}
|
||||||
var articleVO = ArticleVO{}
|
var articleVO = ArticleVO{}
|
||||||
|
var personAge = PersonAge{}
|
||||||
|
|
||||||
func TestAll(t *testing.T) {
|
func TestAll(t *testing.T) {
|
||||||
aorm.Store(&person, &article)
|
aorm.Store(&person, &article)
|
||||||
aorm.Store(&articleVO)
|
aorm.Store(&articleVO)
|
||||||
|
aorm.Store(&personAge)
|
||||||
|
|
||||||
dbList := make([]aorm.DbContent, 0)
|
dbList := make([]aorm.DbContent, 0)
|
||||||
//dbList = append(dbList, testSqlite3Connect())
|
//dbList = append(dbList, testSqlite3Connect())
|
||||||
@@ -104,12 +107,12 @@ func TestAll(t *testing.T) {
|
|||||||
testJoin(dbItem.DriverName, dbItem.DbLink)
|
testJoin(dbItem.DriverName, dbItem.DbLink)
|
||||||
testJoinWithAlias(dbItem.DriverName, dbItem.DbLink)
|
testJoinWithAlias(dbItem.DriverName, dbItem.DbLink)
|
||||||
|
|
||||||
//testGroupBy(dbItem.DriverName, dbItem.DbLink)
|
testGroupBy(dbItem.DriverName, dbItem.DbLink)
|
||||||
//testHaving(dbItem.DriverName, dbItem.DbLink)
|
testHaving(dbItem.DriverName, dbItem.DbLink)
|
||||||
|
return
|
||||||
testOrderBy(dbItem.DriverName, dbItem.DbLink)
|
testOrderBy(dbItem.DriverName, dbItem.DbLink)
|
||||||
break
|
testLimit(dbItem.DriverName, dbItem.DbLink)
|
||||||
//testLimit(dbItem.DriverName, dbItem.DbLink)
|
testLock(dbItem.DriverName, dbItem.DbLink, id2)
|
||||||
//testLock(dbItem.DriverName, dbItem.DbLink, id2)
|
|
||||||
|
|
||||||
testIncrement(dbItem.DriverName, dbItem.DbLink, id2)
|
testIncrement(dbItem.DriverName, dbItem.DbLink, id2)
|
||||||
testDecrement(dbItem.DriverName, dbItem.DbLink, id2)
|
testDecrement(dbItem.DriverName, dbItem.DbLink, id2)
|
||||||
@@ -218,7 +221,7 @@ func testInsert(driver string, db *sql.DB) int64 {
|
|||||||
if errInsert != nil {
|
if errInsert != nil {
|
||||||
panic(driver + " testInsert " + "found err: " + errInsert.Error())
|
panic(driver + " testInsert " + "found err: " + errInsert.Error())
|
||||||
}
|
}
|
||||||
aorm.Use(db).Debug(false).Driver(driver).Insert(&Article{
|
aorm.Use(db).Debug(true).Driver(driver).Insert(&Article{
|
||||||
Type: null.IntFrom(0),
|
Type: null.IntFrom(0),
|
||||||
PersonId: null.IntFrom(id),
|
PersonId: null.IntFrom(id),
|
||||||
ArticleBody: null.StringFrom("文章内容"),
|
ArticleBody: null.StringFrom("文章内容"),
|
||||||
@@ -327,7 +330,7 @@ func testExists(driver string, db *sql.DB, id int64) bool {
|
|||||||
|
|
||||||
//
|
//
|
||||||
//func testTable(driver string, db *sql.DB) {
|
//func testTable(driver string, db *sql.DB) {
|
||||||
// _, err := aorm.Use(db).Debug(false).Driver(driver).Table("person_1").Insert(&Person{Name: null.StringFrom("Cherry")})
|
// _, err := aorm.Use(db).Debug(true).Driver(driver).Table("person_1").Insert(&Person{Name: null.StringFrom("Cherry")})
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// panic(driver + " testTable " + "found err:" + err.Error())
|
// panic(driver + " testTable " + "found err:" + err.Error())
|
||||||
// }
|
// }
|
||||||
@@ -335,7 +338,7 @@ func testExists(driver string, db *sql.DB, id int64) bool {
|
|||||||
//
|
//
|
||||||
//func testSelect(driver string, db *sql.DB) {
|
//func testSelect(driver string, db *sql.DB) {
|
||||||
// var listByFiled []Person
|
// var listByFiled []Person
|
||||||
// err := aorm.Use(db).Debug(false).Driver(driver).Select("name,age").Where(&Person{Age: null.IntFrom(18)}).GetMany(&listByFiled)
|
// err := aorm.Use(db).Debug(true).Driver(driver).Select("name,age").Where(&Person{Age: null.IntFrom(18)}).GetMany(&listByFiled)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// panic(driver + " testSelect " + "found err:" + err.Error())
|
// panic(driver + " testSelect " + "found err:" + err.Error())
|
||||||
// }
|
// }
|
||||||
@@ -345,7 +348,7 @@ func testExists(driver string, db *sql.DB, id int64) bool {
|
|||||||
// var listByFiled []PersonWithArticleCount
|
// var listByFiled []PersonWithArticleCount
|
||||||
//
|
//
|
||||||
// sub := aorm.Sub().Table("article").SelectCount("id", "article_count_tem").WhereRaw("person_id", "=person.id")
|
// sub := aorm.Sub().Table("article").SelectCount("id", "article_count_tem").WhereRaw("person_id", "=person.id")
|
||||||
// err := aorm.Use(db).Debug(false).
|
// err := aorm.Use(db).Debug(true).
|
||||||
// Driver(driver).
|
// Driver(driver).
|
||||||
// SelectExp(&sub, "article_count").
|
// SelectExp(&sub, "article_count").
|
||||||
// Select("*").
|
// Select("*").
|
||||||
@@ -362,7 +365,7 @@ func testExists(driver string, db *sql.DB, id int64) bool {
|
|||||||
//
|
//
|
||||||
// sub := aorm.Sub().Table("article").Select("person_id").GroupBy("person_id").HavingGt("count(person_id)", 0)
|
// sub := aorm.Sub().Table("article").Select("person_id").GroupBy("person_id").HavingGt("count(person_id)", 0)
|
||||||
//
|
//
|
||||||
// err := aorm.Use(db).Debug(false).
|
// err := aorm.Use(db).Debug(true).
|
||||||
// Table("person").
|
// Table("person").
|
||||||
// Driver(driver).
|
// Driver(driver).
|
||||||
// WhereIn("id", &sub).
|
// WhereIn("id", &sub).
|
||||||
@@ -383,7 +386,7 @@ func testExists(driver string, db *sql.DB, id int64) bool {
|
|||||||
// where1 = append(where1, builder.WhereItem{Field: "money", Opt: builder.Eq, Val: 100.15})
|
// where1 = append(where1, builder.WhereItem{Field: "money", Opt: builder.Eq, Val: 100.15})
|
||||||
// where1 = append(where1, builder.WhereItem{Field: "name", Opt: builder.Like, Val: []string{"%", "li", "%"}})
|
// where1 = append(where1, builder.WhereItem{Field: "name", Opt: builder.Like, Val: []string{"%", "li", "%"}})
|
||||||
//
|
//
|
||||||
// err := aorm.Use(db).Debug(false).Driver(driver).Table("person").WhereArr(where1).GetMany(&listByWhere)
|
// err := aorm.Use(db).Debug(true).Driver(driver).Table("person").WhereArr(where1).GetMany(&listByWhere)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// panic(driver + "testWhere" + "found err")
|
// panic(driver + "testWhere" + "found err")
|
||||||
// }
|
// }
|
||||||
@@ -430,48 +433,41 @@ func testJoinWithAlias(driver string, db *sql.DB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//func testGroupBy(driver string, db *sql.DB) {
|
func testGroupBy(driver string, db *sql.DB) {
|
||||||
// var personAge PersonAge
|
var personAgeItem PersonAge
|
||||||
// var where []builder.WhereItem
|
var where []builder.WhereItem
|
||||||
// where = append(where, builder.WhereItem{Field: "type", Opt: builder.Eq, Val: 0})
|
where = append(where, builder.WhereItem{Field: "type", Opt: builder.Eq, Val: 0})
|
||||||
// err := aorm.Use(db).Debug(false).
|
err := aorm.Use(db).Debug(true).
|
||||||
// Table("person").
|
Table(&person).
|
||||||
// Select("age").
|
Select(&person.Age).
|
||||||
// Select("count(age) as age_count").
|
SelectCount(&person.Age, &personAge.AgeCount).
|
||||||
// GroupBy("age").
|
GroupBy(&person.Age).
|
||||||
// WhereArr(where).
|
WhereEq(&person.Type, 0).
|
||||||
// Driver(driver).
|
Driver(driver).
|
||||||
// OrderBy("age", "DESC").
|
OrderBy(&person.Age, builder.Desc).
|
||||||
// GetOne(&personAge)
|
GetOne(&personAgeItem)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// panic(driver + "testGroupBy" + "found err")
|
panic(driver + "testGroupBy" + "found err")
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func testHaving(driver string, db *sql.DB) {
|
func testHaving(driver string, db *sql.DB) {
|
||||||
// var listByHaving []PersonAge
|
var listByHaving []PersonAge
|
||||||
//
|
|
||||||
// var where3 []builder.WhereItem
|
err := aorm.Use(db).Debug(true).Driver(driver).
|
||||||
// where3 = append(where3, builder.WhereItem{Field: "type", Opt: builder.Eq, Val: 0})
|
Table(&person).
|
||||||
//
|
Select(&person.Age).
|
||||||
// var having []builder.WhereItem
|
SelectCount(&person.Age, &personAge.AgeCount).
|
||||||
// having = append(having, builder.WhereItem{Field: "count(age)", Opt: builder.Gt, Val: 4})
|
GroupBy(&person.Age).
|
||||||
//
|
WhereEq(&person.Type, 0).
|
||||||
// err := aorm.Use(db).Debug(false).
|
OrderBy(&person.Age, builder.Desc).
|
||||||
// Table("person").
|
HavingGt(builder.Count, &person.Age, 4).
|
||||||
// Select("age").
|
GetMany(&listByHaving)
|
||||||
// Select("count(age) as age_count").
|
if err != nil {
|
||||||
// GroupBy("age").
|
panic(driver + " testHaving " + "found err")
|
||||||
// WhereArr(where3).
|
}
|
||||||
// Driver(driver).
|
}
|
||||||
// OrderBy("age", "DESC").
|
|
||||||
// HavingArr(having).
|
|
||||||
// GetMany(&listByHaving)
|
|
||||||
// if err != nil {
|
|
||||||
// panic(driver + " testHaving " + "found err")
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
func testOrderBy(driver string, db *sql.DB) {
|
func testOrderBy(driver string, db *sql.DB) {
|
||||||
var listByOrder []Person
|
var listByOrder []Person
|
||||||
err := aorm.Use(db).Debug(true).Driver(driver).
|
err := aorm.Use(db).Debug(true).Driver(driver).
|
||||||
@@ -494,55 +490,50 @@ func testOrderBy(driver string, db *sql.DB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
func testLimit(driver string, db *sql.DB) {
|
||||||
//func testLimit(driver string, db *sql.DB) {
|
var list3 []Person
|
||||||
// var list3 []Person
|
err1 := aorm.Use(db).Debug(true).
|
||||||
// var where1 []builder.WhereItem
|
Table(&person).
|
||||||
// where1 = append(where1, builder.WhereItem{Field: "type", Opt: builder.Eq, Val: 0})
|
WhereEq(&person.Type, 0).
|
||||||
// err1 := aorm.Use(db).Debug(false).
|
Limit(50, 10).
|
||||||
// Table("person").
|
Driver(driver).
|
||||||
// WhereArr(where1).
|
OrderBy(&person.Id, builder.Desc).
|
||||||
// Limit(50, 10).
|
GetMany(&list3)
|
||||||
// Driver(driver).
|
if err1 != nil {
|
||||||
// OrderBy("id", "DESC").
|
panic(driver + "testLimit" + "found err")
|
||||||
// GetMany(&list3)
|
}
|
||||||
// if err1 != nil {
|
|
||||||
// panic(driver + "testLimit" + "found err")
|
var list4 []Person
|
||||||
// }
|
err := aorm.Use(db).Debug(true).
|
||||||
//
|
Driver(driver).
|
||||||
// var list4 []Person
|
Table(&person).
|
||||||
// var where2 []builder.WhereItem
|
WhereEq(&person.Type, 0).
|
||||||
// where2 = append(where2, builder.WhereItem{Field: "type", Opt: builder.Eq, Val: 0})
|
Page(3, 10).
|
||||||
// err := aorm.Use(db).Debug(false).
|
OrderBy(&person.Id, builder.Desc).
|
||||||
// Table("person").
|
GetMany(&list4)
|
||||||
// WhereArr(where2).
|
if err != nil {
|
||||||
// Page(3, 10).
|
panic(driver + "testPage" + "found err")
|
||||||
// Driver(driver).
|
}
|
||||||
// OrderBy("id", "DESC").
|
}
|
||||||
// GetMany(&list4)
|
|
||||||
// if err != nil {
|
func testLock(driver string, db *sql.DB, id int64) {
|
||||||
// panic(driver + "testPage" + "found err")
|
if driver == model.Sqlite3 || driver == model.Mssql {
|
||||||
// }
|
return
|
||||||
//}
|
}
|
||||||
|
var itemByLock Person
|
||||||
|
err := aorm.Use(db).
|
||||||
|
Debug(true).
|
||||||
|
LockForUpdate(true).
|
||||||
|
Table(&person).
|
||||||
|
WhereEq(&person.Id, id).
|
||||||
|
Driver(driver).
|
||||||
|
OrderBy(&person.Id, builder.Desc).
|
||||||
|
GetOne(&itemByLock)
|
||||||
|
if err != nil {
|
||||||
|
panic(driver + "testLock" + "found err")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//func testLock(driver string, db *sql.DB, id int64) {
|
|
||||||
// if driver == model.Sqlite3 || driver == model.Mssql {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// var itemByLock Person
|
|
||||||
// err := aorm.Use(db).
|
|
||||||
// Debug(false).
|
|
||||||
// LockForUpdate(true).
|
|
||||||
// Where(&Person{Id: null.IntFrom(id)}).
|
|
||||||
// Driver(driver).
|
|
||||||
// OrderBy("id", "DESC").
|
|
||||||
// GetOne(&itemByLock)
|
|
||||||
// if err != nil {
|
|
||||||
// panic(driver + "testLock" + "found err")
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
func testIncrement(driver string, db *sql.DB, id int64) {
|
func testIncrement(driver string, db *sql.DB, id int64) {
|
||||||
_, err := aorm.Use(db).Debug(true).Driver(driver).Table(&person).WhereEq(&person.Id, id).Increment(&person.Age, 1)
|
_, err := aorm.Use(db).Debug(true).Driver(driver).Table(&person).WhereEq(&person.Id, id).Increment(&person.Age, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -560,25 +551,25 @@ func testDecrement(driver string, db *sql.DB, id int64) {
|
|||||||
func testValue(driver string, db *sql.DB, id int64) {
|
func testValue(driver string, db *sql.DB, id int64) {
|
||||||
|
|
||||||
var name string
|
var name string
|
||||||
errName := aorm.Use(db).Debug(false).Driver(driver).Table(&person).OrderBy(&person.Id, builder.Desc).WhereEq(&person.Id, id).Value(&person.Name, &name)
|
errName := aorm.Use(db).Debug(true).Driver(driver).Table(&person).OrderBy(&person.Id, builder.Desc).WhereEq(&person.Id, id).Value(&person.Name, &name)
|
||||||
if errName != nil {
|
if errName != nil {
|
||||||
panic(driver + "testValue" + "found err")
|
panic(driver + "testValue" + "found err")
|
||||||
}
|
}
|
||||||
|
|
||||||
var age int64
|
var age int64
|
||||||
errAge := aorm.Use(db).Debug(false).Driver(driver).Table(&person).OrderBy(&person.Id, builder.Desc).WhereEq(&person.Id, id).Value(&person.Age, &age)
|
errAge := aorm.Use(db).Debug(true).Driver(driver).Table(&person).OrderBy(&person.Id, builder.Desc).WhereEq(&person.Id, id).Value(&person.Age, &age)
|
||||||
if errAge != nil {
|
if errAge != nil {
|
||||||
panic(driver + "testValue" + "found err")
|
panic(driver + "testValue" + "found err")
|
||||||
}
|
}
|
||||||
|
|
||||||
var money float32
|
var money float32
|
||||||
errMoney := aorm.Use(db).Debug(false).Driver(driver).Table(&person).OrderBy(&person.Id, builder.Desc).WhereEq(&person.Id, id).Value(&person.Money, &money)
|
errMoney := aorm.Use(db).Debug(true).Driver(driver).Table(&person).OrderBy(&person.Id, builder.Desc).WhereEq(&person.Id, id).Value(&person.Money, &money)
|
||||||
if errMoney != nil {
|
if errMoney != nil {
|
||||||
panic(driver + "testValue" + "found err")
|
panic(driver + "testValue" + "found err")
|
||||||
}
|
}
|
||||||
|
|
||||||
var test float64
|
var test float64
|
||||||
errTest := aorm.Use(db).Debug(false).Driver(driver).Table(&person).OrderBy(&person.Id, builder.Desc).WhereEq(&person.Id, id).Value(&person.Test, &test)
|
errTest := aorm.Use(db).Debug(true).Driver(driver).Table(&person).OrderBy(&person.Id, builder.Desc).WhereEq(&person.Id, id).Value(&person.Test, &test)
|
||||||
if errTest != nil {
|
if errTest != nil {
|
||||||
panic(driver + "testValue" + "found err")
|
panic(driver + "testValue" + "found err")
|
||||||
}
|
}
|
||||||
@@ -620,7 +611,7 @@ func testCount(driver string, db *sql.DB) {
|
|||||||
|
|
||||||
//
|
//
|
||||||
func testSum(driver string, db *sql.DB) {
|
func testSum(driver string, db *sql.DB) {
|
||||||
_, err := aorm.Use(db).Debug(false).Table(&person).WhereEq(&person.Age, 18).Driver(driver).Sum(&person.Age)
|
_, err := aorm.Use(db).Debug(true).Table(&person).WhereEq(&person.Age, 18).Driver(driver).Sum(&person.Age)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(driver + "testSum" + "found err")
|
panic(driver + "testSum" + "found err")
|
||||||
}
|
}
|
||||||
@@ -634,14 +625,14 @@ func testAvg(driver string, db *sql.DB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testMin(driver string, db *sql.DB) {
|
func testMin(driver string, db *sql.DB) {
|
||||||
_, err := aorm.Use(db).Debug(false).Table(&person).WhereEq(&person.Age, 18).Driver(driver).Min(&person.Age)
|
_, err := aorm.Use(db).Debug(true).Table(&person).WhereEq(&person.Age, 18).Driver(driver).Min(&person.Age)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(driver + "testMin" + "found err")
|
panic(driver + "testMin" + "found err")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMax(driver string, db *sql.DB) {
|
func testMax(driver string, db *sql.DB) {
|
||||||
_, err := aorm.Use(db).Debug(false).Table(&person).WhereEq(&person.Age, 18).Driver(driver).Max(&person.Age)
|
_, err := aorm.Use(db).Debug(true).Table(&person).WhereEq(&person.Age, 18).Driver(driver).Max(&person.Age)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(driver + "testMax" + "found err")
|
panic(driver + "testMax" + "found err")
|
||||||
}
|
}
|
||||||
@@ -649,7 +640,7 @@ func testMax(driver string, db *sql.DB) {
|
|||||||
|
|
||||||
//
|
//
|
||||||
//func testExec(driver string, db *sql.DB) {
|
//func testExec(driver string, db *sql.DB) {
|
||||||
// _, err := aorm.Use(db).Debug(false).Driver(driver).Exec("UPDATE person SET name = ? WHERE id=?", "Bob", 3)
|
// _, err := aorm.Use(db).Debug(true).Driver(driver).Exec("UPDATE person SET name = ? WHERE id=?", "Bob", 3)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// panic(driver + "testExec" + "found err")
|
// panic(driver + "testExec" + "found err")
|
||||||
// }
|
// }
|
||||||
@@ -658,7 +649,7 @@ func testMax(driver string, db *sql.DB) {
|
|||||||
//func testTransaction(driver string, db *sql.DB) {
|
//func testTransaction(driver string, db *sql.DB) {
|
||||||
// tx, _ := db.Begin()
|
// tx, _ := db.Begin()
|
||||||
//
|
//
|
||||||
// id, errInsert := aorm.Use(tx).Debug(false).Driver(driver).Insert(&Person{
|
// id, errInsert := aorm.Use(tx).Debug(true).Driver(driver).Insert(&Person{
|
||||||
// Name: null.StringFrom("Alice"),
|
// Name: null.StringFrom("Alice"),
|
||||||
// })
|
// })
|
||||||
//
|
//
|
||||||
@@ -668,7 +659,7 @@ func testMax(driver string, db *sql.DB) {
|
|||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// _, errCount := aorm.Use(tx).Debug(false).Driver(driver).Where(&Person{
|
// _, errCount := aorm.Use(tx).Debug(true).Driver(driver).Where(&Person{
|
||||||
// Id: null.IntFrom(id),
|
// Id: null.IntFrom(id),
|
||||||
// }).Count("*")
|
// }).Count("*")
|
||||||
// if errCount != nil {
|
// if errCount != nil {
|
||||||
@@ -678,7 +669,7 @@ func testMax(driver string, db *sql.DB) {
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// var person Person
|
// var person Person
|
||||||
// errPerson := aorm.Use(tx).Debug(false).Where(&Person{
|
// errPerson := aorm.Use(tx).Debug(true).Where(&Person{
|
||||||
// Id: null.IntFrom(id),
|
// Id: null.IntFrom(id),
|
||||||
// }).Driver(driver).OrderBy("id", "DESC").GetOne(&person)
|
// }).Driver(driver).OrderBy("id", "DESC").GetOne(&person)
|
||||||
// if errPerson != nil {
|
// if errPerson != nil {
|
||||||
@@ -687,7 +678,7 @@ func testMax(driver string, db *sql.DB) {
|
|||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// _, errUpdate := aorm.Use(tx).Debug(false).Driver(driver).Where(&Person{
|
// _, errUpdate := aorm.Use(tx).Debug(true).Driver(driver).Where(&Person{
|
||||||
// Id: null.IntFrom(id),
|
// Id: null.IntFrom(id),
|
||||||
// }).Update(&Person{
|
// }).Update(&Person{
|
||||||
// Name: null.StringFrom("Bob"),
|
// Name: null.StringFrom("Bob"),
|
||||||
@@ -703,7 +694,7 @@ func testMax(driver string, db *sql.DB) {
|
|||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//func testTruncate(driver string, db *sql.DB) {
|
//func testTruncate(driver string, db *sql.DB) {
|
||||||
// _, err := aorm.Use(db).Debug(false).Driver(driver).Table("person").Truncate()
|
// _, err := aorm.Use(db).Debug(true).Driver(driver).Table("person").Truncate()
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// panic(driver + " testTruncate " + "found err")
|
// panic(driver + " testTruncate " + "found err")
|
||||||
// }
|
// }
|
||||||
@@ -714,7 +705,7 @@ func testMax(driver string, db *sql.DB) {
|
|||||||
// var where2 []builder.WhereItem
|
// var where2 []builder.WhereItem
|
||||||
// where2 = append(where2, builder.WhereItem{Field: "o.type", Opt: builder.Eq, Val: 0})
|
// where2 = append(where2, builder.WhereItem{Field: "o.type", Opt: builder.Eq, Val: 0})
|
||||||
// where2 = append(where2, builder.WhereItem{Field: "p.age", Opt: builder.In, Val: []int{18, 20}})
|
// where2 = append(where2, builder.WhereItem{Field: "p.age", Opt: builder.In, Val: []int{18, 20}})
|
||||||
// err := aorm.Use(db).Debug(false).
|
// err := aorm.Use(db).Debug(true).
|
||||||
// Table("article o").
|
// Table("article o").
|
||||||
// LeftJoin("person p", helper.Ul("p.id=o.personId")).
|
// LeftJoin("person p", helper.Ul("p.id=o.personId")).
|
||||||
// Select("o.*").
|
// Select("o.*").
|
||||||
|
|||||||
Reference in New Issue
Block a user