给自定义SQL增加了根据条件判断是否生成的功能
This commit is contained in:
@@ -140,12 +140,13 @@ func TestFuncFetchBy(t *testing.T) {
|
||||
|
||||
// TestCondition 测试sql构建
|
||||
func TestCondition(t *testing.T) {
|
||||
condition := model.Condition{}
|
||||
condition.And(model.AccountColumns.AccountID, ">=", "1")
|
||||
condition.And(model.AccountColumns.UserID, "in", []string{"1", "2", "3"})
|
||||
condition.Or(model.AccountColumns.Type, "in", []string{"1", "2", "3"})
|
||||
query := model.Query{}
|
||||
query.And(model.AccountColumns.AccountID, ">=", "1")
|
||||
query.And(model.AccountColumns.UserID, "in", []string{"1", "2", "3"})
|
||||
query.AndOnCondition(false, model.AccountColumns.AccountID, "in", []string{"5"})
|
||||
query.Or(model.AccountColumns.Type, "in", []string{"1", "2", "3"})
|
||||
|
||||
where, obj := condition.Get()
|
||||
where, obj := query.Get()
|
||||
fmt.Println(where)
|
||||
fmt.Println(obj...)
|
||||
|
||||
@@ -155,6 +156,6 @@ func TestCondition(t *testing.T) {
|
||||
sqldb.Close()
|
||||
}()
|
||||
|
||||
accountMgr := model.AccountMgr(db.Where(condition.Get()))
|
||||
accountMgr := model.AccountMgr(db.Where(where, obj))
|
||||
accountMgr.Gets()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user