Expand description
Query builders: compile Query lists, and the
builder’s own clauses, into statements for each dialect.
A Builder is generic over its Dialect; the dialects are type
aliases (MySql, …). Features only some dialects have are traits in
feature: a builder has their methods when its dialect implements them.
| PHP | Rust |
|---|---|
Builder (abstract), Builder\SQL (abstract) | Builder, Dialect, SqlDialect |
Builder\MySQL | MySql (MySqlDialect) |
Builder\MariaDB | MariaDb (MariaDbDialect) |
Builder\PostgreSQL, PostgreSQL\UpdateFrom, PostgreSQL\DeleteUsing, PostgreSQL\MergeTarget | PostgreSql (PostgreSqlDialect), UpdateFrom, DeleteUsing, MergeTarget |
Builder\SQLite | Sqlite (SqliteDialect) |
Builder\ClickHouse, ClickHouse\AsofOperator, ClickHouse\Format, ClickHouse\FormattedInsertStatement, ClickHouse::DELETE_MODE_* | ClickHouse (ClickHouseDialect), AsofOperator, Format, FormattedInsertStatement, DeleteMode |
Builder\MongoDB, MongoDB\Operation, MongoDB\PipelineStage, MongoDB\UpdateOperation, MongoDB\UpdateOperator, hint()’s string|array | MongoDb (MongoDbDialect), Operation, PipelineStage, UpdateOperation, UpdateOperator, IndexHint |
Builder\Statement | Statement |
Builder\Condition, Builder\Binding | Condition, Binding |
Builder\JoinBuilder, Builder\JoinOn, Builder\JoinType | JoinBuilder, JoinOn, JoinType |
Builder\Case\Expression, Case\Kind, Case\Operator, Case\WhenClause | CaseExpression, Kind, Operator, WhenClause |
Builder\CteClause, Builder\UnionClause, Builder\UnionType | CteClause, UnionClause, UnionType |
Builder\WindowFrame, Builder\WindowDefinition, Builder\WindowSelect | WindowFrame, WindowDefinition, WindowSelect |
Builder\LockMode, Builder\VectorMetric | LockMode, VectorMetric |
Builder\SubSelect, Builder\WhereInSubquery, Builder\ExistsSubquery, Builder\LateralJoin | SubSelect, WhereInSubquery, ExistsSubquery, LateralJoin |
Builder\ColumnPredicate, Builder\MergeClause, Builder\SpatialDistanceFilter | ColumnPredicate, MergeClause, SpatialDistanceFilter |
Builder\Feature\* | feature |
Builder as a parameter type | AnyBuilder |
Modules§
- feature
- What only some dialects can do: each feature is a trait a dialect
implements, and
Builderhas the feature’s methods for the dialects that implement it (soMySql::new().hint(...)compiles and a ClickHouse builder hasprewhere, while a MongoDB builder has neither).
Structs§
- Binding
- A binding captured while compiling: the value and the column it was compared to, when known (ClickHouse types named parameters by column).
- Builder
- A query builder for one dialect: from a table, with queries (filters,
ordering, pagination, aggregates, joins) and the builder’s own clauses
(subqueries, raw SQL, window functions, CTEs, unions), compiled by
Builder::buildinto aStatement; also inserts, updates, deletes and upserts. - Case
Expression - A
CASEexpression:WHENclauses in order, an optionalELSEand an alias. - Click
House Dialect - The ClickHouse dialect and its own state.
- Column
Predicate left operator right, both columns.- Condition
- A SQL fragment with its bindings.
- Core
- The state of a builder that every dialect shares: what PHP’s abstract
Builderand its traits hold. - CteClause
- A common table expression, compiled.
- Delete
Using - The table of
DELETE ... USING, with an extra condition. - Exists
Subquery [NOT] EXISTS (subquery).- Explain
Options - The options of
EXPLAINbeyondANALYZE, for the dialects that have them. - Flavor
- How a builder compiles some filters, as
utopia-php/database’s builder subclasses do. The default compiles as this library does. - Formatted
Insert Statement - An
INSERT INTO table [(columns)] FORMAT nameenvelope (no bindings), with the format, the columns and, fromBuilder::bulk_insert, the serialized rows to send with it. - IdCollation
- Document ids are unique in the collation of their unique indexes, and an
engine only uses an index for a comparison made in the index’s
collation, so equality on an id column (
IN,NOT IN), and an=,!=or<>of a join’s ON on id columns, compares in that collation. - Join
Builder - The conditions of one join: column comparisons (
on) and conditions with bindings (where, raw SQL). - JoinOn
- A column-to-column condition of a join built with a
JoinBuilder. - Lateral
Join [LEFT] JOIN LATERAL (subquery) AS alias ON true.- Maria
DbDialect - The MariaDB dialect: MySQL’s state.
- Merge
Clause - A
MERGEaction and its bindings. - Merge
Target - The target, source and condition of a
MERGE. - Mongo
DbDialect - The MongoDB dialect, and its own state: update operators, pipeline stages, search stages and the index hint.
- MySql
Dialect - The MySQL dialect.
- MySql
State - MySQL’s own state: the join of a multi-table update or delete.
- Postgre
SqlDialect - The PostgreSQL dialect and its own state.
- Scope
Binding - What
Scope::bindregisters on a builder. - Spatial
Distance Filter - The geometry, distance and unit of a
distance*query. - Sqlite
Dialect - The SQLite dialect.
- Sqlite
Flavor - SQLite as
utopia-php/databasecompiles it: everyLIKEdeclares the backslash escape,REGEXPcalls the user function the adapter registers, and array filters match JSON elements. Its id columns compare in their collation throughFlavor::ids. - Statement
- A compiled statement: the SQL (or MongoDB command JSON) with
?placeholders and the values bound to them, in order. - SubSelect
- A builder used as a source:
FROM (subquery) AS alias, a select-list subquery. - Union
Clause - A compiled member of a compound select.
- Update
From - The table joined by
UPDATE ... FROM, with an extra condition. - Update
Operation - An update operator with its fields (field => value).
- When
Clause - One
WHEN ... THEN ...clause. - Where
InSubquery column [NOT] IN (subquery).- Window
Definition - A named window:
WINDOW name AS (...). - Window
Frame - A window frame:
ROWS UNBOUNDED PRECEDING,RANGE BETWEEN ... AND .... - Window
Select - A window function in the select list.
Enums§
- Arg
- An argument of a
Step. - Asof
Operator - The inequality of an
ASOF JOIN. - AstDialect
- Which AST serializer a builder converts with (
toAst/fromAst). - Delete
Mode - Which
DELETEformBuilder::deleteemits. - Format
- A ClickHouse input format for bulk inserts.
- Index
Hint - The index a query must use: a name, or a key pattern (
{"name": 1}). - Join
Type - A kind of join, as its SQL keyword.
- Kind
- What a
WHENclause tests. - Lock
Mode - A row lock, as its SQL.
- Operation
- The operation a compiled document runs.
- Operator
- A comparison of a
WHENclause. - Pipeline
Stage - An aggregation pipeline stage (and the
$textoperator). - Ret
- What a
Stepreturns. - Step
- A method of PHP’s builders that a subclass can override.
- Union
Type - How a compound select combines its members.
- Update
Operator - An update operator.
- Vector
Metric - A vector distance metric (pgvector).
Traits§
- AnyBuilder
- Any builder, as other builders and schemas take one (a subquery, a union member, a view’s query).
- AstWriter
- What writes the SQL
fromAst()keeps raw: the dialect’sSerializer, or the one a subclass’screateAstSerializer()returns. - Dialect
- What a dialect changes in the shared compilation: identifier quoting,
random order, regex, and the clauses only some dialects emit. Every hook
has the behaviour of PHP’s base
Builderunless the dialect overrides it. - MySql
Family - What MySQL and MariaDB share: their state, and the geometry constructor.
- Overrides
- The overrides of a builder’s steps.
- Scope
- How a builder’s
from()reads a collection: the table it is stored under, and the hooks that map its attributes to columns and keep its statements to a tenant. - SqlDialect
- The hooks a SQL dialect implements: how it compiles search, spatial and JSON predicates, and its conflict clause.
Functions§
- geometry_
to_ wkt - A coordinate array as WKT:
[x, y]a point, a list of points a line, a list of closed rings of at least 4 points a polygon. Fails withError::Validationon any other shape, or a point that is not an[x, y]pair of finite numbers.
Type Aliases§
- After
Build - A callback run on every built statement, returning the statement to use.
- Before
Build - A callback run at the start of every build, with the builder.
- Click
House - A ClickHouse builder.
- Executor
- What runs a statement: given it, returns its rows (an array) or an affected-row count (an integer).
- MariaDb
- A MariaDB builder.
- MongoDb
- A MongoDB builder: compiles to operation documents (JSON).
- MySql
- A MySQL builder.
- Object
Path Check - A check of a path into an object attribute (see
Flavor::object_path). - Postgre
Sql - A PostgreSQL builder.
- Sqlite
- A SQLite builder.