[feat] 规范名称 NewCondtionExpr => NewExpr
This commit is contained in:
parent
1d047e071b
commit
91d88930c2
@ -200,7 +200,7 @@ func (this ConditionExpr) IsIgnoreEmptyParma(m contracts.ConditionTokenValue) bo
|
||||
return false
|
||||
}
|
||||
|
||||
func NewConditionExpr(rResource, rField, token string, operator contracts.ConditionOperator, tType contracts.ConditionTokenType, ignoreEmptyParma bool, fn, fnParam string) contracts.ConditionExpr {
|
||||
func NewExpr(rResource, rField, token string, operator contracts.ConditionOperator, tType contracts.ConditionTokenType, ignoreEmptyParma bool, fn, fnParam string) contracts.ConditionExpr {
|
||||
return &ConditionExpr{
|
||||
operator: operator,
|
||||
field: rField,
|
||||
|
74
contracts/contracts.go
Normal file
74
contracts/contracts.go
Normal file
@ -0,0 +1,74 @@
|
||||
package contracts
|
||||
|
||||
import (
|
||||
"git.fsdpf.net/go/db"
|
||||
"git.fsdpf.net/go/req"
|
||||
)
|
||||
|
||||
type ConditionType string
|
||||
type ConditionOperator string
|
||||
type ConditionTokenType string
|
||||
|
||||
const (
|
||||
OR ConditionType = "OR"
|
||||
AND ConditionType = "AND"
|
||||
)
|
||||
|
||||
const (
|
||||
SQL ConditionTokenType = "sql"
|
||||
FUNC ConditionTokenType = "func"
|
||||
PARAM ConditionTokenType = "param"
|
||||
STRING ConditionTokenType = "string"
|
||||
)
|
||||
|
||||
const (
|
||||
IS_NULL ConditionOperator = "IS NULL"
|
||||
IS_NOT_NULL ConditionOperator = "IS NOT NULL"
|
||||
EQ ConditionOperator = "="
|
||||
NE ConditionOperator = "!="
|
||||
GT ConditionOperator = ">"
|
||||
GE ConditionOperator = ">="
|
||||
LT ConditionOperator = "<"
|
||||
LE ConditionOperator = "<="
|
||||
LIKE ConditionOperator = "LIKE"
|
||||
NOT_LIKE ConditionOperator = "NOT LIKE"
|
||||
IN ConditionOperator = "IN"
|
||||
NOT_IN ConditionOperator = "NOT IN"
|
||||
REGEXP ConditionOperator = "REGEXP"
|
||||
NOT_REGEXP ConditionOperator = "NOT REGEXP"
|
||||
)
|
||||
|
||||
type Condition interface {
|
||||
Type() ConditionType
|
||||
IsEmpty() bool
|
||||
IsNotEmpty() bool
|
||||
IsAlwaysRight() bool
|
||||
ToSql(ConditionTokenValue) db.Expression
|
||||
AppendTo(Condition)
|
||||
SetExpr(ConditionExpr) Condition
|
||||
SetCondition(Condition) Condition
|
||||
SetMatchPrefix(string) Condition
|
||||
GetFields(operator ConditionOperator, types ...ConditionTokenType) map[string]string
|
||||
GetFieldsValue(m ConditionTokenValue, isWithResource bool) map[string]any
|
||||
}
|
||||
|
||||
type ConditionExpr interface {
|
||||
GetField() string
|
||||
GetFieldResource() string
|
||||
GetOperator() ConditionOperator
|
||||
|
||||
SetMatchPrefix(string) ConditionExpr
|
||||
|
||||
AppendTo(Condition)
|
||||
ToSql(m ConditionTokenValue) db.Expression
|
||||
GetTokenName() string
|
||||
GetTokenType() ConditionTokenType
|
||||
GetTokenValue(ConditionTokenValue) any
|
||||
GetTokenSqlValue(ConditionTokenValue) string
|
||||
IsIgnoreEmptyParma(ConditionTokenValue) bool
|
||||
}
|
||||
|
||||
type ConditionTokenValue interface {
|
||||
GetParam(k string) req.GlobalParams
|
||||
GetGlobalParamsUser() req.User
|
||||
}
|
@ -26,7 +26,7 @@ func TestEngine(t *testing.T) {
|
||||
|
||||
cond1 := condition.New(contracts.AND, "条件1")
|
||||
|
||||
cond1.SetExpr(condition.NewConditionExpr(
|
||||
cond1.SetExpr(condition.NewExpr(
|
||||
"TestTable", "age", "age",
|
||||
contracts.EQ, contracts.PARAM,
|
||||
false, "", "",
|
||||
@ -68,7 +68,7 @@ func TestRelationEngine(t *testing.T) {
|
||||
}
|
||||
|
||||
cond1 := condition.New(contracts.AND, "条件1").
|
||||
SetExpr(condition.NewConditionExpr(
|
||||
SetExpr(condition.NewExpr(
|
||||
"TestTable", "age", "age",
|
||||
contracts.EQ, contracts.PARAM,
|
||||
false, "", "",
|
||||
@ -80,12 +80,12 @@ func TestRelationEngine(t *testing.T) {
|
||||
})
|
||||
|
||||
cond2 := condition.New(contracts.OR, "条件2").
|
||||
SetExpr(condition.NewConditionExpr(
|
||||
SetExpr(condition.NewExpr(
|
||||
"TestTableA", "age", "age",
|
||||
contracts.EQ, contracts.PARAM,
|
||||
false, "", "",
|
||||
)).
|
||||
SetExpr(condition.NewConditionExpr(
|
||||
SetExpr(condition.NewExpr(
|
||||
"TestTable", "age", "age",
|
||||
contracts.EQ, contracts.PARAM,
|
||||
false, "", "",
|
||||
|
Loading…
Reference in New Issue
Block a user