DoydoQuery v2
English
English
  • Introduction
  • Quickstart
  • API
    • CRUD
    • Association Service
  • Complex Query
  • Object Concepts
    • Query Object
      • PageQuery
      • Predicate-Suffix Field
      • Logic-Suffix Field
      • Subquery Field
      • E-R Query Field
      • Custom Condition Field
    • Entity Object
      • Enum Column
      • Foreign Key
    • Patch Object
    • View Object
      • Column Mapping
      • Natural Join
  • Having Object
  • Advanced
    • Dialect
    • Pessimistic lock
  • Optimistic Lock
  • Web
    • Configuration
    • Controller
    • Service
    • Cache
    • Sorting
    • Validation
    • User ID injection
Powered by GitBook
On this page

Was this helpful?

  1. Object Concepts
  2. Query Object

Logic-Suffix Field

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

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

userQuery := UserQuery{UserOr: &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 (?, ?, ?) OR deleted = ?)" args="[1 4 12 true]"

UsersOr *[]UserQuery

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

Check:

PreviousPredicate-Suffix FieldNextSubquery Field

Last updated 7 months ago

Was this helpful?

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