1 Star 0 Fork 8

jqmtony/toyorm

forked from bigpigeon/toyorm 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
search_test.go 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
bigpigeon 提交于 2018-12-09 00:06 . 1. feature update
/*
* Copyright 2018. bigpigeon. All rights reserved.
* Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file.
*/
package toyorm
import (
"reflect"
"testing"
)
func TestSearchToExecValue(t *testing.T) {
dialect := DefaultDialect{}
{
model := NewModel(reflect.ValueOf(TestSearchTable{}))
t1 := NewSearchTree(NewSearchBranch(ExprOr)).Fill(
NewSearchTree(NewSearchBranch(ExprAnd)).Fill(
NewSearchTree(NewSearchLeaf(ExprEqual, model.GetFieldWithName("A").ToFieldValue(reflect.ValueOf("22")))),
NewSearchTree(NewSearchLeaf(ExprEqual, model.GetFieldWithName("B").ToFieldValue(reflect.ValueOf("33")))),
),
NewSearchTree(NewSearchBranch(ExprAnd)).Fill(
NewSearchTree(NewSearchLeaf(ExprEqual, model.GetFieldWithName("C").ToFieldValue(reflect.ValueOf("55")))),
NewSearchTree(NewSearchLeaf(ExprEqual, model.GetFieldWithName("D").ToFieldValue(reflect.ValueOf("66")))),
),
)
t.Log(dialect.SearchExec(t1.ToStack()))
}
{
model := NewModel(reflect.ValueOf(TestSearchTable{}))
t2 := NewSearchTree(NewSearchBranch(ExprOr)).Fill(
NewSearchTree(NewSearchBranch(ExprNot)).Fill(
NewSearchTree(NewSearchLeaf(ExprEqual, model.GetFieldWithName("A").ToFieldValue(reflect.ValueOf("22")))),
nil,
),
NewSearchTree(NewSearchBranch(ExprAnd)).Fill(
NewSearchTree(NewSearchLeaf(ExprEqual, model.GetFieldWithName("B").ToFieldValue(reflect.ValueOf("55")))),
NewSearchTree(NewSearchLeaf(ExprEqual, model.GetFieldWithName("C").ToFieldValue(reflect.ValueOf("66")))),
),
)
t2List := t2.ToStack()
t2List = t2List.Condition(model.GetFieldWithName("D").ToFieldValue(reflect.ValueOf("909")), ExprEqual, ExprAnd)
t.Logf("%#v", dialect.SearchExec(t2List))
}
{
model := NewModel(reflect.ValueOf(TestSearchTable{}))
t1 := NewSearchTree(NewSearchBranch(ExprOr)).Fill(
NewSearchTree(NewSearchBranch(ExprAnd)).Fill(
NewSearchTree(NewSearchLeaf(ExprEqual, model.GetFieldWithName("A").ToColumnAlias("t1").ToFieldValue(reflect.ValueOf("22")))),
NewSearchTree(NewSearchLeaf(ExprEqual, model.GetFieldWithName("B").ToColumnAlias("t1").ToFieldValue(reflect.ValueOf("33")))),
),
NewSearchTree(NewSearchBranch(ExprAnd)).Fill(
NewSearchTree(NewSearchLeaf(ExprEqual, model.GetFieldWithName("C").ToColumnAlias("t2").ToFieldValue(reflect.ValueOf("55")))),
NewSearchTree(NewSearchLeaf(ExprEqual, model.GetFieldWithName("D").ToColumnAlias("t2").ToFieldValue(reflect.ValueOf("66")))),
),
)
t.Log(dialect.SearchExec(t1.ToStack()))
t.Logf("%#v\n", t1.ToStack())
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jqmtony/toyorm.git
git@gitee.com:jqmtony/toyorm.git
jqmtony
toyorm
toyorm
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385