Implementation:APIJSON APIJSON AbstractSQLConfig Column Quoting
| Knowledge Sources | |
|---|---|
| Domains | ORM, SQL_Generation, Multi_Database |
| Last Updated | 2026-10-11 00:00 GMT |
Overview
Concrete column projection builder that parses the @column directive into a dialect-specific SQL column string with quoting, aliases, and function support, provided by the APIJSON ORM framework.
Description
The gainColumnString' method on AbstractSQLConfig transforms the @column directive value (e.g., "id,name,date+1:tomorrow") into a SQL column projection string with:
- Dialect-specific quoting: Columns are wrapped with the database's quote character (`` ` `` for MySQL, " for PostgreSQL/Oracle)
- Column aliases: The :' syntax maps to AS (e.g., "date+1:tomorrow" → "date"+1 AS "tomorrow")
- SQL functions: Aggregate and scalar functions are preserved (e.g., "count(*):total" → count(*) AS "total")
- @raw passthrough: Columns listed in @raw are passed through unmodified
- HEAD method optimization: For HEAD/HEADS, only the column name is used for counting
Usage
Called internally by gainSelectSQL() during SQL generation. The column list is set on the SQLConfig from the @column directive in the request JSON.
Code Reference
Source Location
- Repository: APIJSON
- File: src/main/java/apijson/orm/AbstractSQLConfig.java
Signature
public List<String> getColumn()
public String gainColumnString() throws Exception
public String gainColumnString(boolean inSQLJoin) throws Exception
Parameters:
- inSQLJoin - Whether generating column string for a SQL JOIN (affects column prefixing)
Returns: String - SQL column projection string (e.g., "`id`,`name`,`date`+1 AS `tomorrow`")
Import
import apijson.orm.AbstractSQLConfig;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| column | List<String> | No | Column list from @column directive |
| quote | String | Yes | Dialect-specific quote character |
| inSQLJoin | boolean | No | Whether in SQL JOIN context |
| getRaw() | List<String> | No | @raw columns to pass through unmodified |
Outputs
| Name | Type | Description |
|---|---|---|
| return | String | SQL column projection string |
Usage Examples
Basic Column Projection
// @column: "id,name,userId"
// MySQL: `id`,`name`,`userId`
// PostgreSQL: "id","name","userId"
With Alias and Function
// @column: "id,date+1:tomorrow,count(*):total"
// MySQL: `id`,`date`+1 AS `tomorrow`,count(*) AS `total`
@raw Passthrough
// @column: "id,date_format(date,'%Y-%m-%d'):formatted"
// @raw: "formatted"
// The "formatted" column is passed through without quoting:
// `id`,date_format(`date`,'%Y-%m-%d') AS formatted