Predicate-Suffix Field

Mapping

GoooQo uses a predicate suffix mapping method to map fields in query objects to basic query conditions. Each basic query condition consists of a column name, a comparison operator, and a value. The format of the field name in the query object is a column name plus one of the comparison operator alias. All assigned fields in a query instance will be mapped to the corresponding query conditions and spliced ​​into a query clause.

Examples

Here are two examples of the predicate-suffix field mapping:

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]"

Check the predicate suffix table for all supported suffixes by GoooQo.

Predicate Suffix Table

SuffixField NameValueSQL Condition

(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’

Last updated