Logic-Suffix Field

Mapping

By default, the query conditions corresponding to the fields of the query object are connected by AND in GoooQo.

Or Suffix

If we want to use the logical operator OR to connect the query conditions, we need to define a struct or array with the suffix Or in the query object.

GoooQo supports the following three definitions:

type UserQuery struct {
	PageQuerygo
	//...
	NameStartOr *[]string
	UserOr      *UserQuery
	UsersOr     *[]UserQuery
}

NameStartOr *[]string

userQuery := UserQuery{NameStartOr: &[]string{"Bob", "John", "Tim"}}
users, err := userDataAccess.Query(ctx, userQuery)
// SQL="SELECT id, name, score, memo, deleted FROM t_user 
// WHERE (name LIKE ? OR name LIKE ? OR name LIKE ?)" args="[Bob% John% Tim%]"

UserOr *UserQuery

UsersOr *[]UserQuery

And Suffix

When the name of a field ends with And, the logical operator connecting multiple query conditions is AND.

UserAnd *UserQuery

Articles

https://blog.doyto.win/post/goooqo-or-clause-en/

Last updated

Was this helpful?