给自定义SQL增加了根据条件判断是否生成的功能

This commit is contained in:
jiang4869
2022-01-06 23:38:48 +08:00
parent f79e1becc7
commit deb37930bd
3 changed files with 73 additions and 46 deletions

View File

@@ -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()
}