Skip to content

MySQLGrammar ​

MySQL-specific query grammar implementation. Compiles query components into SQL statements for MySQL. Supports features like CTEs, ON DUPLICATE KEY UPDATE, GROUP BY, ORDER BY, LIMIT/OFFSET, and schema introspection.

compileSelect ​

Compiles a SELECT query into SQL.

Parameters ​

NameDescription
queryQuery components including ctes, columns, from, joins,
           wheres, groups, havings, orders, limit, offset. |

returns — The compiled SQL SELECT statement.

compileInsert ​

Compiles an INSERT query into SQL, supporting ON DUPLICATE KEY UPDATE.

Parameters ​

NameDescription
queryContains table and values, and optional onDuplicateKey map.

returns — The compiled SQL INSERT statement.

compileUpdate ​

Compiles an UPDATE query into SQL, with optional ORDER BY and LIMIT.

Parameters ​

NameDescription
queryContains table, values, wheres, orders, and limit.

returns — The compiled SQL UPDATE statement.

compileDelete ​

Compiles a DELETE query into SQL, with optional ORDER BY and LIMIT.

Parameters ​

NameDescription
queryContains table, wheres, orders, and limit.

returns — The compiled SQL DELETE statement.

compileWheres ​

Compiles WHERE clauses into SQL. Supports basic, IN, NOT IN, BETWEEN, NULL checks, EXISTS, and raw.

Parameters ​

NameDescription
wheresArray of where clause objects.

returns — The compiled WHERE clause string.

compileJoins ​

Compiles JOIN clauses into SQL.

Parameters ​

NameDescription
joinsArray of join clause objects.

returns — The compiled JOIN clause string.

compileCtes ​

Compiles CTEs into SQL.

Parameters ​

NameDescription
ctesArray of CTE definition objects.

returns — The compiled CTE list string.

wrapTable ​

Wraps a table name with backticks.

Parameters ​

NameDescription
tableTable name, optionally schema-qualified.

returns — The wrapped table name.

wrapColumn ​

Wraps a column name with backticks.

Parameters ​

NameDescription
columnColumn name, optionally table-qualified.

returns — The wrapped column name.

parameter ​

Returns the parameter placeholder.

Parameters ​

NameDescription
_The value to bind (ignored).

returns — The placeholder string '?'.

getColumnType ​

Maps a ColumnDefinition to its MySQL column type.

Parameters ​

NameDescription
columnColumn definition object with type, length, precision, scale.

returns — The SQL column type.

formatDefault ​

Formats default values for SQL.

Parameters ​

NameDescription
defDefault value (string or number).

returns — Formatted default clause.

compileCreateTable ​

Compiles a CREATE TABLE statement for MySQL.

Parameters ​

NameDescription
definitionTable definition containing name and columns.

returns — SQL CREATE TABLE string.

compileAlterTable ​

Compiles an ALTER TABLE statement for MySQL. Supports adding columns only.

Parameters ​

NameDescription
definitionTableDefinition with new columns.

returns — SQL ALTER TABLE string.

compileTableExists ​

Compiles a table existence check.

Parameters ​

NameDescription
tableTable name to check.

returns — SQL SELECT against information_schema.tables.

compileColumnExists ​

Compiles a column existence check.

Parameters ​

NameDescription
tableTable name.
columnColumn name.

returns — SQL SELECT against information_schema.columns.

rename ​

Renames a table in MySQL.

Parameters ​

NameDescription
fromCurrent table name.
toNew table name.

returns — Promise rejected with SQL to execute; driver layer should run it.

Released under the MIT License.