Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:APIJSON APIJSON Subquery Class

From Leeroopedia
Knowledge Sources
Domains ORM, SQL_Generation, Subquery
Last Updated 2026-10-11 00:00 GMT

Overview

Concrete configuration class that encapsulates a subquery specification parsed from key{}@ reference keys, holding the source table, range (ALL/ANY), target key, and inner SQLConfig, provided by the APIJSON ORM framework.

Description

The Subquery class represents a SQL subquery parsed from request JSON keys ending with {}@ (e.g., "id{}@"). It holds:

  • path - The parsing path where this subquery was encountered
  • originKey - The original key (e.g., "id{}@")
  • originValue - The original value map from the request
  • from - The source table name for the subquery (e.g., "Comment")
  • range - Whether to use ALL or ANY (maps to IN ALL/IN ANY)
  • key - The target key without the @ suffix (e.g., "id{}")
  • config - The inner SQLConfig that generates the subquery's SQL

When ENABLE_WITH_AS is true, subqueries may be generated as WITH AS (CTE) expressions instead of inline subqueries.

Usage

Created internally by AbstractObjectParser.onParse() when processing key{}@ reference keys. Used by AbstractSQLConfig during SQL generation to embed the subquery in the WHERE clause.

Code Reference

Source Location

  • Repository: APIJSON
  • File: src/main/java/apijson/orm/Subquery.java

Signature

public class Subquery<T, M extends Map<String, Object>, L extends List<Object>> {
    private String path;
    private String originKey;
    private M originValue;
    private String from;
    private String range;
    private String key;
    private SQLConfig<T, M, L> config;
    
    // Getters and setters for all fields
    public String gainPath();
    public String gainOriginKey();
    public M gainOriginValue();
    public String gainFrom();
    public String gainRange();
    public String gainKey();
    public SQLConfig<T, M, L> gainConfig();
}

Import

import apijson.orm.Subquery;

I/O Contract

Inputs

Name Type Required Description
from String Yes Source table for subquery
range String No "ALL" or "ANY"
key String Yes Target key (e.g., "id{}")
config SQLConfig Yes Inner query config

Outputs

Name Type Description
(fields) - Configuration data consumed by SQL generator

Usage Examples

Subquery in Request

// Request JSON:
// {
//   "Moment": {
//     "id{}@": {
//       "from": "Comment",
//       "Comment": { "momentId@": "/Moment/id", "userId": 82001 }
//     }
//   }
// }

// Parsed to Subquery:
// Subquery {
//   from: "Comment",
//   range: null,  // default: IN
//   key: "id{}",
//   config: SQLConfig { table: "Comment", where: { userId: 82001 } }
// }

// Generated SQL:
// SELECT * FROM `Moment` WHERE `id` IN (
//   SELECT `momentId` FROM `Comment` WHERE `userId` = 82001
// )

WITH AS (CTE) Form

// When ENABLE_WITH_AS = true:
// WITH subquery_alias AS (
//   SELECT `momentId` FROM `Comment` WHERE `userId` = 82001
// )
// SELECT * FROM `Moment` WHERE `id` IN (SELECT * FROM subquery_alias)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment