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 AbstractSQLConfig Dialect Selection

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

Overview

Concrete database dialect selector that resolves the target database type from the @database directive, determines dialect family (MySQL/PostgreSQL/T-SQL), and controls quoting style and SQL syntax variations, provided by the APIJSON ORM framework.

Description

The dialect selection methods on 'AbstractSQLConfig determine which database syntax to use for SQL generation:

  • setDatabase(String): Sets the database type name (e.g., "MYSQL", "POSTGRESQL", "ORACLE", "KINGBASE")
  • gainSQLDatabase(): Returns the database type, falling back to DEFAULT_DATABASE if not set
  • Dialect family checks: isMSQL(), isPSQL(), isTSQL() group databases by SQL syntax family
  • Specific database checks: isMySQL(), isPostgreSQL(), isOracle(), isSQLServer(), isClickHouse(), isDb2(), isDameng(), isKingBaseOracle(), isKingBaseMySQL(), isKingbaseSQLServer()

The dialect determines:

  • Quote character: `` ` `` for MySQL family, " for PostgreSQL/Oracle family
  • LIMIT syntax: LIMIT n OFFSET m vs OFFSET m ROWS FETCH NEXT n ROWS ONLY
  • UPSERT strategy: ON DUPLICATE KEY UPDATE (MySQL) vs ON CONFLICT DO UPDATE (PostgreSQL) vs MERGE INTO (Oracle/SQL Server)
  • Special SQL: ClickHouse uses ALTER TABLE ... UPDATE instead of UPDATE

Usage

Set via the @database directive in the request JSON, or globally via DEFAULT_DATABASE. Called by SQL generation methods to select appropriate syntax.

Code Reference

Source Location

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

Signature

public AbstractSQLConfig<T, M, L> setDatabase(String database)

@NotNull
public String gainSQLDatabase()

// Dialect family checks:
public boolean isMSQL()   // MySQL, TiDB, MariaDB, SQLite, TDengine, KingbaseMySQL
public boolean isPSQL()   // PostgreSQL, CockroachDB, openGauss, InfluxDB, TimescaleDB, QuestDB, DuckDB
public boolean isTSQL()   // Oracle, SQL Server, DB2, KingbaseOracle, KingbaseSQLServer

// Specific checks:
public boolean isMySQL()
public boolean isPostgreSQL()
public boolean isOracle()
public boolean isSQLServer()
public boolean isClickHouse()
public boolean isDb2()
public boolean isDameng()

Import

import apijson.orm.AbstractSQLConfig;

I/O Contract

Inputs

Name Type Required Description
database String No Database type name (e.g., "MYSQL")
DEFAULT_DATABASE String Yes Fallback when not specified

Outputs

Name Type Description
gainSQLDatabase() String Active database type
getQuote() String Dialect-specific quote character

Usage Examples

Setting Database via Request

// Request: { "@database": "POSTGRESQL", "User": { "id": 1 } }
// AbstractParser extracts @database and calls:
// setGlobalDatabase("POSTGRESQL");

// In SQLConfig:
// gainSQLDatabase() returns "POSTGRESQL"
// getQuote() returns "\""
// SQL: SELECT "id" FROM "User" WHERE "id" = 1

Dialect-Specific SQL

// MySQL: SELECT `id` FROM `User` WHERE `id` = 1 LIMIT 10 OFFSET 0
// PostgreSQL: SELECT "id" FROM "User" WHERE "id" = 1 LIMIT 10 OFFSET 0
// Oracle: SELECT "id" FROM "User" WHERE "id" = 1 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY
// ClickHouse: ALTER TABLE `User` UPDATE SET ... (for PUT)

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

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