Skip to main content

The sql Namespace

Everything @sqb/builder exports is also available bundled under a single sql namespace import, which is convenient when you'd rather not name every symbol individually or want to avoid naming collisions with your own code:

import { sql } from '@sqb/builder';

const query = sql.Select('id', 'given_name')
.from('customers')
.where(sql.Eq('active', true));

import { Select, Eq } from '@sqb/builder' and sql.Select / sql.Eq above refer to the exact same classes — sql is just an alternate, namespaced way to reach them. The tables below list every symbol it carries, grouped the way the source itself groups them, each with a one-line description and a link to its full API reference page.

Statements

SymbolDescription
sql.SelectBuilds a SELECT query — columns, FROM, JOIN, WHERE, GROUP BY, ORDER BY, LIMIT/OFFSET.
sql.InsertBuilds an INSERT statement from a plain object or another Select.
sql.UpdateBuilds an UPDATE statement with a SET clause and conditions.
sql.DeleteBuilds a DELETE statement with conditions.
sql.UnionCombines two Select queries with UNION/UNION ALL.
sql.ReturningQueryBase class for statements that support a RETURNING clause (Insert, Update, Delete).
sql.QueryThe base class every statement extends — .generate(), .values(), .comment(), and the 'serialize' event hook live here.

See Select Statement, Insert Statement, Update Statement, and Delete Statement for full guides.

Elements

Building blocks used inside statements — columns, table references, joins, and SQL functions.

SymbolDescription
sql.FieldReferences a column, optionally qualified with a table and aliased with .as().
sql.BaseFieldAbstract base every column-like element (Field, Count, Case, …) extends.
sql.TableNameReferences a table, optionally schema-qualified and aliased.
sql.RawEmbeds a literal, unescaped SQL fragment.
sql.ParamA named bind parameter (:name), with an optional data type and array flag.
sql.CaseA CASE WHEN ... THEN ... ELSE ... END expression.
sql.CoalesceA COALESCE(...) expression.
sql.CountA COUNT(...) aggregate expression.
sql.MaxA MAX(...) aggregate expression.
sql.MinA MIN(...) aggregate expression.
sql.UpperAn UPPER(...) expression.
sql.LowerA LOWER(...) expression.
sql.SequenceReferences a database sequence's next/current value.
sql.StringAggA STRING_AGG/GROUP_CONCAT-style aggregate expression.
sql.GroupColumnA column reference used inside GROUP BY.
sql.OrderColumnA column reference used inside ORDER BY, with direction/nulls placement.
sql.ReturningColumnA column reference used inside a RETURNING clause.
sql.JoinBase JOIN element — configurable join type and condition.
sql.InnerJoinAn INNER JOIN.
sql.LeftJoinA LEFT JOIN.
sql.LeftOuterJoinA LEFT OUTER JOIN.
sql.RightJoinA RIGHT JOIN.
sql.RightOuterJoinA RIGHT OUTER JOIN.
sql.OuterJoinA generic OUTER JOIN.
sql.FullOuterJoinA FULL OUTER JOIN.
sql.CrossJoinA CROSS JOIN.

See Columns and Table References for Field/TableName/ GroupColumn/OrderColumn/ReturningColumn, Functions and Expressions for Case/Coalesce/Count/Max/Min/Upper/Lower/StringAgg/Sequence, and Joins for the join elements.

Operators

Used inside .where() and anywhere else a condition is expected.

SymbolDescription
sql.OperatorAbstract base every operator extends.
sql.LogicalOperatorAbstract base for And/Or, combining a list of conditions.
sql.CompOperatorAbstract base for comparison operators (Eq, Gt, Like, …).
sql.AndCombines conditions with AND. .where() does this implicitly for multiple arguments.
sql.OrCombines conditions with OR.
sql.NotNegates a condition with NOT.
sql.Eq= equality.
sql.Ne!= inequality.
sql.Gt> greater-than.
sql.Gte>= greater-or-equal.
sql.Lt< less-than.
sql.Lte<= less-or-equal.
sql.BetweenBETWEEN x AND y.
sql.NotBetweenNOT BETWEEN x AND y.
sql.InIN (...).
sql.NotInNOT IN (...).
sql.LikeLIKE.
sql.NotLikeNOT LIKE.
sql.ILikeCase-insensitive LIKE (dialect-dependent).
sql.NotILikeCase-insensitive NOT LIKE (dialect-dependent).
sql.IsIS (typically IS NULL/IS TRUE/IS FALSE).
sql.IsNotIS NOT.
sql.ExistsEXISTS (subquery).
sql.NotExistsNOT EXISTS (subquery).
sql.MatchFull-text match condition (dialect-dependent).

See Operators and Conditions for a full guide with examples and each operator's string-shorthand key (e.g. '=', '!=', '!between').

Everything else

enums.ts, types.ts, and the string-keyed Operators map are exported directly from @sqb/builder (not re-exported under sql) — see Enums and Interfaces in the API reference.