The "Grammar" is a collection of functions which help to reliably compile the various pieces of SQL into a valid, escaped query. These functions are combined with dialect specific "Grammar" functions to keep the interface database agnostic.
The list of different components
Compiles the current query builder.
Gets the cleaned bindings.
if (bindings[i] == void 0) continue;
Compiles the select
statement, or nested sub-selects
by calling each of the component compilers, trimming out
the empties, and returning a generated query string.
If there is a transaction, and we have either forUpdate
or forShare
specified,
call the appropriate additions to the select statement.
Compiles the columns with aggregate functions.
Compiles the columns in the query, specifying if an item was distinct.
Compiles the from
tableName portion of the query.
Compiles all each of the join
clauses on the query,
including any nested join queries.
Compiles all where
statements on the query.
Compile the "union" queries attached to the main query.
Compiles a nested where clause.
Compiles a nested where clause.
Compiles a basic where clause.
Compiles a basic exists clause.
Compiles a basic not exists clause.
Compiles a where in clause.
Compiles a where not in clause.
Compiles a sub-where in clause.
Compiles a sub-where not in clause.
Where between.
Compiles the group by
columns.
Compiles the having
statements.
Compiles the order by
statements.
Compiles the limit
statements.
Compiles an offset
statement on the query.
Compiles an insert
query, allowing for multiple
inserts using a single query statement.
If there are any "where" clauses, we need to omit any bindings that may have been associated with them.
Depending on the type of where
clause, this will appropriately
remove any binding caused by "where" constraints, allowing the same
query to be used for insert
and update
without issue.
Compiles an update
query.
Compiles a delete
query.
Compiles a truncate
query.
Adds a for update
clause to the query, relevant with transactions.
Adds a for share
clause to the query, relevant with transactions.
Puts the appropriate wrapper around a value depending on the database engine, unless it's a knex.raw value, in which case it's left alone.
Grammar