谓词后缀字段

谓词后缀

GoooQo采用谓词后缀映射方法,将查询对象中的字段中以预定义谓词结尾的字段映射为基本查询条件。每个基本查询条件由列名、比较运算符和比较值组成。

在查询对象中,用于映射基本查询条件的字段,命名格式为列名加谓词的别名,用于映射查询条件的列名和比较运算符,查询条件的比较值为字段的赋值。 一个查询对象实例中已赋值的字段会被映射为对应的查询条件,并由逻辑运算符AND拼接为查询子句。

以下为后缀映射的两个示例:

userQuery := UserQuery{Deleted: P(true)}
users, err := userDataAccess.Query(ctx, userQuery)
// SQL="SELECT id, name, score, memo, deleted FROM t_user WHERE deleted = ?" args="[true]"

userQuery := UserQuery{IdIn: &[]int64{1, 4, 12}, Deleted: P(true)}
users, err := userDataAccess.Query(ctx, userQuery)
// SQL="SELECT id, name, score, memo, deleted FROM t_user WHERE id IN (?, ?, ?) AND deleted = ?" args="[1 4 12 true]"

预定义谓词谓词后缀请参考谓词后缀表

谓词后缀表

谓词后缀字段名称赋值SQL查询条件

(EMPTY)

id

5

id = 5

Eq

idEq

5

id = 5

Not

idNot

5

id != 5

Ne

idNe

5

id <> 5

Gt

idGt

5

id > 5

Ge

idGe

5

id >= 5

Lt

idLt

5

id < 5

Le

idLe

5

id <= 5

NotIn

idNotIn

[1,2,3]

id NOT IN (1,2,3)

In

idIn

[1,2,3]

id IN (1,2,3)

Null

memoNull

false

memo IS NOT NULL

Null

memoNull

true

memo IS NULL

NotLike

nameNotLike

"arg"

name NOT LIKE '%arg%'

Like

nameLike

"arg"

name LIKE '%arg%'

NotStart

nameNotStart

"arg"

name NOT LIKE 'arg%'

Start

nameStart

"arg"

name LIKE 'arg%'

NotEnd

nameNotEnd

"arg"

name NOT LIKE '%arg'

End

nameEnd

"arg"

name LIKE '%arg'

NotContain

nameNotContain

"arg"

name NOT LIKE '%arg%’

Contain

nameContain

"arg"

name LIKE '%arg%’

Rx

nameRx

"arg\d"

name REGEXP 'arg\d’

最后更新于