GoooQo v0.2.3
HomeGitHubDemo
English
English
  • Introduction
  • Quickstart
  • API
    • Connection
    • Transaction
    • CRUD
    • Association Service
  • Entity Mapping
    • Entity Object
    • Related Entities
  • Query Mapping
    • Query Object
      • Predicate-Suffix Field
      • Logic-Suffix Field
      • Subquery Field
      • E-R Query Field
      • Custom Condition Field
    • Page Query
  • Aggregate Query
    • View Object
    • Having
    • Natural Join
    • Outer Join
    • Nested View
  • Advanced
    • Dialect
    • Locking
  • Related Resources
    • Articles
      • From ORM to OQM: An Object-Only SQL Construction Solution
      • Introduction to GoooQo
      • How to express `select * from user where id = ? or name = ? and age = ?` in GoooQo
Powered by GitBook
On this page
  • Mapping
  • Tags Examples
  • Field Name Resolution

Was this helpful?

Edit on GitHub
  1. Query Mapping
  2. Query Object

Subquery Field

Mapping

For a general subquery,score > (SELECT avg(score) FROM t_user WHERE deleted = ?), is divided into three parts in OQM for mapping:

  • score >

  • SELECT avg(score) FROM t_user

  • WHERE clause

The first part score >can be mapped using the field name scoreGtXxx, just like a normal predicate suffix field. The string defined after the predicate suffix is ​​only used to distinguish duplicate field names and will be ignored during mapping.

The second part contains a column and a table name, which are static and unchanging. GoooQo provides two tags to save this information: One is subquery, which is used to define the native subquery statement; The other is the combination of the tags select and from, which saves the column name and table name respectively.

The third part is another WHERE clause, which can be mapped through a query object. Therefore, we define the field type as the corresponding query object and map the value to the WHERE clause in the subquery through the query object mapping method.

Tags Examples

Here are some examples of subquery field definitions (since v0.2.0):

ScoreLtAvg *UserQuery `subquery:"select avg(score) from t_user"`
ScoreLtAny *UserQuery `subquery:"SELECT score FROM t_user"`
ScoreLtAll *UserQuery `subquery:"select score from UserEntity"`
ScoreGtAvg *UserQuery `select:"avg(score)" from:"UserEntity"`

Field Name Resolution

Since 0.2.0, GoooQo also supports resolving SELECT from the field name.

Field name format

<column><predicate><[aggregate]column>Of<entity>

Examples

ScoreInScoreOfUser    *UserQuery //score IN (SELECT score FROM t_user WHERE ...)
ScoreGtAvgScoreOfUser *UserQuery //score > (SELECT AVG(score) FROM t_user WHERE ...)

In these examples, we need to register a mapping relationship to map User to t_user:

rdb.RegisterEntity("User", "t_user")
PreviousLogic-Suffix FieldNextE-R Query Field

Last updated 8 months ago

Was this helpful?