Skip to main content

Module builder

Module builder 

Source
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.

PHPRust
Builder (abstract), Builder\SQL (abstract)Builder, Dialect, SqlDialect
Builder\MySQLMySql (MySqlDialect)
Builder\MariaDBMariaDb (MariaDbDialect)
Builder\PostgreSQL, PostgreSQL\UpdateFrom, PostgreSQL\DeleteUsing, PostgreSQL\MergeTargetPostgreSql (PostgreSqlDialect), UpdateFrom, DeleteUsing, MergeTarget
Builder\SQLiteSqlite (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|arrayMongoDb (MongoDbDialect), Operation, PipelineStage, UpdateOperation, UpdateOperator, IndexHint
Builder\StatementStatement
Builder\Condition, Builder\BindingCondition, Binding
Builder\JoinBuilder, Builder\JoinOn, Builder\JoinTypeJoinBuilder, JoinOn, JoinType
Builder\Case\Expression, Case\Kind, Case\Operator, Case\WhenClauseCaseExpression, Kind, Operator, WhenClause
Builder\CteClause, Builder\UnionClause, Builder\UnionTypeCteClause, UnionClause, UnionType
Builder\WindowFrame, Builder\WindowDefinition, Builder\WindowSelectWindowFrame, WindowDefinition, WindowSelect
Builder\LockMode, Builder\VectorMetricLockMode, VectorMetric
Builder\SubSelect, Builder\WhereInSubquery, Builder\ExistsSubquery, Builder\LateralJoinSubSelect, WhereInSubquery, ExistsSubquery, LateralJoin
Builder\ColumnPredicate, Builder\MergeClause, Builder\SpatialDistanceFilterColumnPredicate, MergeClause, SpatialDistanceFilter
Builder\Feature\*feature
Builder as a parameter typeAnyBuilder

Modules§

feature
What only some dialects can do: each feature is a trait a dialect implements, and Builder has the feature’s methods for the dialects that implement it (so MySql::new().hint(...) compiles and a ClickHouse builder has prewhere, 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::build into a Statement; also inserts, updates, deletes and upserts.
CaseExpression
A CASE expression: WHEN clauses in order, an optional ELSE and an alias.
ClickHouseDialect
The ClickHouse dialect and its own state.
ColumnPredicate
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 Builder and its traits hold.
CteClause
A common table expression, compiled.
DeleteUsing
The table of DELETE ... USING, with an extra condition.
ExistsSubquery
[NOT] EXISTS (subquery).
ExplainOptions
The options of EXPLAIN beyond ANALYZE, 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.
FormattedInsertStatement
An INSERT INTO table [(columns)] FORMAT name envelope (no bindings), with the format, the columns and, from Builder::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.
JoinBuilder
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.
LateralJoin
[LEFT] JOIN LATERAL (subquery) AS alias ON true.
MariaDbDialect
The MariaDB dialect: MySQL’s state.
MergeClause
A MERGE action and its bindings.
MergeTarget
The target, source and condition of a MERGE.
MongoDbDialect
The MongoDB dialect, and its own state: update operators, pipeline stages, search stages and the index hint.
MySqlDialect
The MySQL dialect.
MySqlState
MySQL’s own state: the join of a multi-table update or delete.
PostgreSqlDialect
The PostgreSQL dialect and its own state.
ScopeBinding
What Scope::bind registers on a builder.
SpatialDistanceFilter
The geometry, distance and unit of a distance* query.
SqliteDialect
The SQLite dialect.
SqliteFlavor
SQLite as utopia-php/database compiles it: every LIKE declares the backslash escape, REGEXP calls the user function the adapter registers, and array filters match JSON elements. Its id columns compare in their collation through Flavor::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.
UnionClause
A compiled member of a compound select.
UpdateFrom
The table joined by UPDATE ... FROM, with an extra condition.
UpdateOperation
An update operator with its fields (field => value).
WhenClause
One WHEN ... THEN ... clause.
WhereInSubquery
column [NOT] IN (subquery).
WindowDefinition
A named window: WINDOW name AS (...).
WindowFrame
A window frame: ROWS UNBOUNDED PRECEDING, RANGE BETWEEN ... AND ....
WindowSelect
A window function in the select list.

Enums§

Arg
An argument of a Step.
AsofOperator
The inequality of an ASOF JOIN.
AstDialect
Which AST serializer a builder converts with (toAst/fromAst).
DeleteMode
Which DELETE form Builder::delete emits.
Format
A ClickHouse input format for bulk inserts.
IndexHint
The index a query must use: a name, or a key pattern ({"name": 1}).
JoinType
A kind of join, as its SQL keyword.
Kind
What a WHEN clause tests.
LockMode
A row lock, as its SQL.
Operation
The operation a compiled document runs.
Operator
A comparison of a WHEN clause.
PipelineStage
An aggregation pipeline stage (and the $text operator).
Ret
What a Step returns.
Step
A method of PHP’s builders that a subclass can override.
UnionType
How a compound select combines its members.
UpdateOperator
An update operator.
VectorMetric
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’s Serializer, or the one a subclass’s createAstSerializer() 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 Builder unless the dialect overrides it.
MySqlFamily
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 with Error::Validation on any other shape, or a point that is not an [x, y] pair of finite numbers.

Type Aliases§

AfterBuild
A callback run on every built statement, returning the statement to use.
BeforeBuild
A callback run at the start of every build, with the builder.
ClickHouse
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.
ObjectPathCheck
A check of a path into an object attribute (see Flavor::object_path).
PostgreSql
A PostgreSQL builder.
Sqlite
A SQLite builder.