代码拉取完成,页面将自动刷新
package tag
import (
"gitee.com/go-genie/kvcondition"
"gitee.com/go-genie/sqlx"
"gitee.com/go-genie/sqlx-pg/pgbuilder"
"gitee.com/go-genie/sqlx/builder"
)
func SelectByKVCondition(db sqlx.DBExecutor, kvc kvcondition.KVCondition, modelWithTag ModelWithTag, idCol *builder.Column) *pgbuilder.StmtSelect {
if kvc.Node == nil {
return nil
}
s := pgbuilder.Use(db)
keyCol := modelWithTag.FieldKey()
valueCol := modelWithTag.FieldValue()
var visit func(node kvcondition.Node) builder.SqlCondition
visit = func(node kvcondition.Node) builder.SqlCondition {
switch n := node.(type) {
case *kvcondition.Condition:
switch n.Operator {
case kvcondition.ConditionOperatorOR:
return builder.Or(
idCol.In(s.Select(idCol).From(modelWithTag).Where(visit(n.Left))),
visit(n.Right),
)
case kvcondition.ConditionOperatorAND:
return builder.And(
idCol.In(s.Select(idCol).From(modelWithTag).Where(visit(n.Left))),
visit(n.Right),
)
}
return nil
case *kvcondition.Rule:
k := string(n.Key)
v := string(n.Value)
switch n.Operator {
case kvcondition.OperatorExists:
return keyCol.Eq(k)
case kvcondition.OperatorEqual:
return builder.And(
keyCol.Eq(k),
valueCol.Eq(v),
)
case kvcondition.OperatorNotEqual:
return builder.And(
keyCol.Eq(k),
valueCol.Neq(v),
)
case kvcondition.OperatorContains:
return builder.And(
keyCol.Eq(k),
valueCol.Like(v),
)
case kvcondition.OperatorStartsWith:
return builder.And(
keyCol.Eq(k),
valueCol.RightLike(v),
)
case kvcondition.OperatorEndsWith:
return builder.And(
keyCol.Eq(k),
valueCol.LeftLike(v),
)
}
return nil
}
return nil
}
return s.Select(idCol).From(modelWithTag).Where(visit(kvc.Node))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。