Skip to main content

Builder

Struct Builder 

Source
pub struct Builder<D: Dialect> { /* private fields */ }
Expand description

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.

The dialects are type aliases: MySql and the others. Features only some dialects have are traits in feature.

PHP: the abstract Utopia\Query\Builder and its subclasses.

Implementations§

Source§

impl<D: Dialect> Builder<D>

Source

pub fn from( &mut self, table: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

The table (and its alias) to select from, update or delete from; an empty table makes a select without FROM.

PHP: from($table, $alias).

On a builder with a Scope, a non-empty table is a collection id read through the scope (see Builder::scope).

Source

pub fn take_refusal(&mut self) -> Option<Error>

The refusal a call returning the builder kept for the next statement, taken: PHP throws it from that call (from() of another collection or alias on a bound builder, into() and the dialects’ multi-table writes once a collection is bound).

PHP: ScopesCollections::from(), requireUnbound().

Source

pub fn from_none(&mut self) -> &mut Self

A select without FROM.

PHP: fromNone().

Source

pub fn from_sub( &mut self, subquery: impl AnyBuilder + 'static, alias: impl Into<String>, ) -> &mut Self

FROM (subquery) AS alias.

PHP: fromSub().

Source

pub fn from_sub_boxed( &mut self, subquery: Box<dyn AnyBuilder>, alias: impl Into<String>, ) -> &mut Self

Builder::from_sub with a boxed builder.

Source

pub fn select_sub( &mut self, subquery: Box<dyn AnyBuilder>, alias: impl Into<String>, ) -> &mut Self

(subquery) AS alias in the select list.

PHP: selectSub().

Source

pub fn filter_where_in( &mut self, column: impl Into<String>, subquery: Box<dyn AnyBuilder>, ) -> &mut Self

column IN (subquery).

PHP: filterWhereIn().

Source

pub fn filter_where_not_in( &mut self, column: impl Into<String>, subquery: Box<dyn AnyBuilder>, ) -> &mut Self

column NOT IN (subquery).

PHP: filterWhereNotIn().

Source

pub fn filter_exists(&mut self, subquery: Box<dyn AnyBuilder>) -> &mut Self

EXISTS (subquery).

PHP: filterExists().

Source

pub fn filter_not_exists(&mut self, subquery: Box<dyn AnyBuilder>) -> &mut Self

NOT EXISTS (subquery).

PHP: filterNotExists().

Source

pub fn select<S: Into<String>>( &mut self, columns: impl IntoIterator<Item = S>, ) -> &mut Self

The columns to select.

PHP: select(array $columns).

Source

pub fn select_raw( &mut self, expression: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

A raw select expression with its bindings.

PHP: select(string $expression, $bindings), selectRaw().

Source

pub fn distinct(&mut self) -> &mut Self

SELECT DISTINCT.

PHP: distinct().

Source

pub fn filter(&mut self, queries: impl IntoIterator<Item = Query>) -> &mut Self

Adds queries (filters, or any query).

PHP: filter().

Source

pub fn queries(&mut self, queries: impl IntoIterator<Item = Query>) -> &mut Self

Adds queries of any kind.

PHP: queries().

Source

pub fn sort_asc( &mut self, attribute: impl Into<String>, nulls: Option<NullsPosition>, ) -> &mut Self

ORDER BY attribute ASC (with NULLS FIRST/LAST).

PHP: sortAsc().

Source

pub fn sort_desc( &mut self, attribute: impl Into<String>, nulls: Option<NullsPosition>, ) -> &mut Self

ORDER BY attribute DESC (with NULLS FIRST/LAST).

PHP: sortDesc().

Source

pub fn sort_random(&mut self) -> &mut Self

Random order.

PHP: sortRandom().

Source

pub fn limit(&mut self, value: i64) -> &mut Self

LIMIT.

PHP: limit().

Source

pub fn offset(&mut self, value: i64) -> &mut Self

OFFSET.

PHP: offset().

Source

pub fn fetch(&mut self, count: i64, with_ties: bool) -> &mut Self

FETCH FIRST count ROWS ONLY (or WITH TIES).

PHP: fetch().

Source

pub fn page(&mut self, page: i64, per_page: i64) -> Result<&mut Self>

The limit and offset of page page (from 1) of per_page rows.

PHP: page().

Source

pub fn cursor_after(&mut self, row: Value) -> &mut Self

Rows after a cursor row (an array with _cursor, or a row object).

PHP: cursorAfter().

Source

pub fn cursor_before(&mut self, row: Value) -> &mut Self

Rows before a cursor row.

PHP: cursorBefore().

Source

pub fn when( &mut self, condition: bool, callback: impl FnOnce(&mut Self) -> Result<()>, ) -> Result<&mut Self>

Runs callback with the builder when condition holds.

PHP: when().

Source

pub fn before_build( &mut self, callback: impl Fn(&mut Self) -> Result<()> + Send + Sync + 'static, ) -> &mut Self

A callback run with the builder at the start of every build.

PHP: beforeBuild().

Source

pub fn after_build( &mut self, callback: impl Fn(Statement) -> Result<Statement> + Send + Sync + 'static, ) -> &mut Self

A callback run on every built statement, returning the statement to use.

PHP: afterBuild().

Source

pub fn after_build_owned( &mut self, callback: impl Fn(usize, Statement) -> Result<Statement> + Send + Sync + 'static, ) -> &mut Self

As Self::after_build, with the owner of the builder that built.

Source

pub fn set_executor(&mut self, executor: Executor) -> &mut Self

What runs the statements this builder builds (Builder::execute).

PHP: setExecutor().

Source

pub fn explain(&mut self, analyze: bool) -> Result<Statement>

EXPLAIN (or EXPLAIN ANALYZE) of the select.

PHP: explain($analyze).

Source

pub fn explain_with( &mut self, analyze: bool, options: &ExplainOptions, ) -> Result<Statement>

EXPLAIN with the dialect’s options (format; PostgreSQL’s verbose and buffers).

PHP: explain($analyze, ...) of MySQL and PostgreSQL.

Source

pub fn execute(&mut self) -> Result<Value>

Builds the select and runs it with the executor.

PHP: execute().

Source

pub fn to_raw_sql(&mut self) -> Result<String>

The select with its bindings inlined: strings quoted by the dialect (' doubled, and \ doubled outside PostgreSQL and SQLite), numbers as PHP prints them, booleans as 1/0, anything else NULL. For logs only: never execute it.

PHP: toRawSql().

Source

pub fn to_raw_sql_widened(&mut self) -> Result<String>

As Builder::to_raw_sql, for a builder whose text holds a character for each byte, as the PHP extension passes a string that is not UTF-8: the bytes of a string binding are written the same way.

Source

pub fn binding_list(&self) -> &[Binding]

The bindings so far, each with the column it was bound against.

PHP: the protected $bindings.

Source

pub fn set_binding_list(&mut self, bindings: Vec<Binding>) -> &mut Self

Replaces the bindings.

Source

pub fn set_pending(&mut self, queries: Vec<Query>) -> &mut Self

Replaces the queries to compile.

PHP: the protected $pendingQueries.

Source

pub fn resolved_attributes(&self) -> impl Iterator<Item = (&str, &str)>

The attributes resolved so far, and what each resolved to.

PHP: the protected $resolvedAttributeCache.

Source

pub fn set_resolved_attributes( &mut self, resolved: impl IntoIterator<Item = (String, String)>, ) -> &mut Self

Replaces the resolved attributes.

Source

pub fn bindings(&mut self) -> Vec<Value>

The bindings of the last statement built.

PHP: getBindings().

Source

pub fn reset(&mut self) -> &mut Self

Clears everything but hooks and the executor.

PHP: reset().

Source

pub fn build(&mut self) -> Result<Statement>

Compiles the select.

PHP: build().

Source

pub fn count( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

count(attribute) (* counts rows) as alias.

PHP: count().

Source

pub fn count_distinct( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

COUNT(DISTINCT attribute).

PHP: countDistinct().

Source

pub fn sum( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

SUM.

PHP: sum().

Source

pub fn avg( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

AVG.

PHP: avg().

Source

pub fn min( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

MIN.

PHP: min().

Source

pub fn max( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

MAX.

PHP: max().

Source

pub fn group_by<S: Into<String>>( &mut self, columns: impl IntoIterator<Item = S>, ) -> &mut Self

GROUP BY.

PHP: groupBy().

Source

pub fn group_by_time_bucket( &mut self, attribute: impl Into<String>, interval: &str, ) -> Result<&mut Self>

Groups by attribute cut into windows of interval.

PHP: groupByTimeBucket().

Source

pub fn having(&mut self, queries: impl IntoIterator<Item = Query>) -> &mut Self

HAVING conditions (aggregate aliases resolve to their expressions).

PHP: having().

Source

pub fn join( &mut self, table: impl Into<String>, left: &str, right: &str, operator: &str, alias: impl Into<String>, ) -> &mut Self

JOIN table [AS alias] ON left operator right.

PHP: join().

Source

pub fn left_join( &mut self, table: impl Into<String>, left: &str, right: &str, operator: &str, alias: impl Into<String>, ) -> &mut Self

LEFT JOIN.

PHP: leftJoin().

Source

pub fn right_join( &mut self, table: impl Into<String>, left: &str, right: &str, operator: &str, alias: impl Into<String>, ) -> &mut Self

RIGHT JOIN.

PHP: rightJoin().

Source

pub fn join_where( &mut self, table: impl Into<String>, callback: impl FnOnce(&mut JoinBuilder) -> Result<()>, join_type: JoinType, alias: impl Into<String>, ) -> Result<&mut Self>

A join whose conditions callback builds on a JoinBuilder.

PHP: joinWhere().

Source

pub fn union(&mut self, other: &mut dyn AnyBuilder) -> Result<&mut Self>

UNION with another builder’s select (built now).

PHP: union().

Source

pub fn union_all(&mut self, other: &mut dyn AnyBuilder) -> Result<&mut Self>

UNION ALL.

PHP: unionAll().

Source

pub fn intersect(&mut self, other: &mut dyn AnyBuilder) -> Result<&mut Self>

INTERSECT.

PHP: intersect().

Source

pub fn intersect_all(&mut self, other: &mut dyn AnyBuilder) -> Result<&mut Self>

INTERSECT ALL.

PHP: intersectAll().

Source

pub fn except(&mut self, other: &mut dyn AnyBuilder) -> Result<&mut Self>

EXCEPT.

PHP: except().

Source

pub fn except_all(&mut self, other: &mut dyn AnyBuilder) -> Result<&mut Self>

EXCEPT ALL.

PHP: exceptAll().

Source

pub fn with<S: Into<String>>( &mut self, name: impl Into<String>, query: &mut dyn AnyBuilder, columns: impl IntoIterator<Item = S>, ) -> Result<&mut Self>

WITH name [(columns)] AS (query) (built now).

PHP: with().

Source

pub fn with_recursive<S: Into<String>>( &mut self, name: impl Into<String>, query: &mut dyn AnyBuilder, columns: impl IntoIterator<Item = S>, ) -> Result<&mut Self>

WITH RECURSIVE name AS (query).

PHP: withRecursive().

Source

pub fn with_recursive_seed_step<S: Into<String>>( &mut self, name: impl Into<String>, seed: &mut dyn AnyBuilder, step: &mut dyn AnyBuilder, columns: impl IntoIterator<Item = S>, ) -> Result<&mut Self>

WITH RECURSIVE name AS (seed UNION ALL step).

PHP: withRecursiveSeedStep().

Source

pub fn into(&mut self, table: impl Into<String>) -> &mut Self

The table to insert into.

PHP: into().

Source

pub fn insert_as(&mut self, alias: impl Into<String>) -> &mut Self

INSERT INTO table AS alias.

PHP: insertAs().

Source

pub fn set(&mut self, row: Array) -> Result<&mut Self>

A row to insert (column => value), or the values of an update.

PHP: set().

Source

pub fn on_conflict<K: Into<String>, U: Into<String>>( &mut self, keys: impl IntoIterator<Item = K>, update_columns: impl IntoIterator<Item = U>, ) -> &mut Self

The conflict target and the columns an upsert updates.

PHP: onConflict().

Source

pub fn from_select<S: Into<String>>( &mut self, columns: impl IntoIterator<Item = S>, source: Box<dyn AnyBuilder>, ) -> &mut Self

INSERT INTO table (columns) SELECT ... from source (built at insert time).

PHP: fromSelect().

Source

pub fn insert(&mut self) -> Result<Statement>

Compiles the insert.

PHP: insert().

Source

pub fn insert_default_values(&mut self) -> Result<Statement>

INSERT INTO table DEFAULT VALUES (MySQL: () VALUES ()).

PHP: insertDefaultValues().

Source

pub fn insert_select(&mut self) -> Result<Statement>

INSERT INTO table (columns) SELECT ....

PHP: insertSelect().

Source

pub fn update(&mut self) -> Result<Statement>

Compiles the update.

PHP: update().

Source

pub fn delete(&mut self) -> Result<Statement>

Compiles the delete.

PHP: delete().

Source

pub fn add_hook(&mut self, hook: impl Into<Hook>) -> Result<&mut Self>

Adds a hook: a filter, an attribute resolver, a join filter, or several at once.

PHP: addHook().

Source

pub fn select_window( &mut self, function: impl Into<String>, alias: impl Into<String>, partition_by: Option<Vec<String>>, order_by: Option<Vec<String>>, window_name: Option<String>, frame: Option<WindowFrame>, ) -> Result<&mut Self>

A window function in the select list: function OVER (...) AS alias, or OVER window_name. The function must look like NAME(args).

PHP: selectWindow().

Source

pub fn window( &mut self, name: impl Into<String>, partition_by: Option<Vec<String>>, order_by: Option<Vec<String>>, frame: Option<WindowFrame>, ) -> &mut Self

A named window: WINDOW name AS (...).

PHP: window().

Source

pub fn pending(&self) -> &[Query]

The queries added so far.

Source§

impl<D: Dialect> Builder<D>

Source

pub fn to_ast(&mut self) -> Result<Select>

The builder’s select as a syntax tree: columns and aggregates, table, joins, filters, grouping, HAVING, ordering, limit, offset, DISTINCT and CTEs (each CTE’s SQL parsed with the standard tokenizer).

PHP: Builder::toAst().

Source

pub fn from_ast(select: &Select) -> Result<Self>

A builder with the select select describes: its table, columns (aggregates become aggregate queries, other expressions raw selects), joins, filters, grouping, HAVING, ordering, limit, offset, CTEs and DISTINCT. Expressions without a query equivalent are kept as raw SQL, written by the dialect’s serializer.

PHP: Builder::fromAst().

Source

pub fn from_ast_with(select: &Select, writer: &dyn AstWriter) -> Result<Self>

Self::from_ast, writing what stays raw SQL with writer.

PHP: fromAst() in a subclass that overrides createAstSerializer().

Source§

impl Builder<ClickHouseDialect>

Source

pub fn apply_named_typed_bindings(&self, statement: Statement) -> Statement

statement with its ? placeholders named and typed, when named bindings are on.

PHP: applyNamedTypedBindings().

Source§

impl Builder<ClickHouseDialect>

Source

pub fn prewhere( &mut self, queries: impl IntoIterator<Item = Query>, ) -> &mut Self

PREWHERE filters, evaluated before the other columns are read.

PHP: prewhere().

Source

pub fn final_(&mut self) -> &mut Self

FINAL after the table (merges the data parts first).

PHP: final().

Source

pub fn sample(&mut self, fraction: f64) -> Result<&mut Self>

SAMPLE fraction after the table; the fraction must be in (0, 1).

PHP: sample().

Source

pub fn settings<K: AsRef<str>, V: AsRef<str>>( &mut self, settings: impl IntoIterator<Item = (K, V)>, ) -> Result<&mut Self>

SETTINGS key=value, ... at the end of selects and deletes; keys are identifiers, values letters, digits, _ and ..

PHP: settings().

Source

pub fn bulk_insert( &mut self, format: Format, rows: impl IntoIterator<Item = Value>, columns: Vec<String>, ) -> Result<FormattedInsertStatement>

The INSERT INTO table [(columns)] FORMAT format envelope with the rows serialized in format. Each row must be an array; the columns default to the first row’s keys.

PHP: bulkInsert().

use utopia_query::builder::{ClickHouse, Format};
use utopia_query::{Array, Value};

let mut row = Array::default();
row.set("id".into(), Value::Int(1));
let insert = ClickHouse::new().from("events", "").bulk_insert(Format::JSONEachRow, [Value::Array(row)], Vec::new())?;
assert_eq!(insert.query, "INSERT INTO `events` (`id`) FORMAT JSONEachRow");
assert_eq!(insert.body.as_deref(), Some(r#"{"id":1}"#));
use Utopia\Query\Builder\ClickHouse;
use Utopia\Query\Builder\ClickHouse\Format;

$insert = (new ClickHouse())->from('events')->bulkInsert(Format::JSONEachRow, [['id' => 1]]);
echo $insert->query, "\n", $insert->body, "\n";
// INSERT INTO `events` (`id`) FORMAT JSONEachRow
// {"id":1}
Source

pub fn insert_format<S: Into<String>>( &mut self, format: &str, columns: impl IntoIterator<Item = S>, ) -> Result<&mut Self>

Makes Builder::insert (and Builder::formatted_insert) emit the FORMAT format envelope only, for a body sent separately; the columns default to the keys of the first row set.

PHP: insertFormat().

Source

pub fn formatted_insert(&mut self) -> Result<Option<FormattedInsertStatement>>

The FORMAT envelope of an Builder::insert_format insert (with no body), or None when no format was set.

PHP: insert(), which returns a FormattedInsertStatement after insertFormat().

Source

pub fn use_named_bindings(&mut self, enabled: bool) -> &mut Self

Rewrites the ? placeholders of built statements to ClickHouse’s {paramN:Type} and fills Statement::named_bindings.

PHP: useNamedBindings().

use utopia_query::Query;
use utopia_query::builder::ClickHouse;

let statement = ClickHouse::new()
    .use_named_bindings(true)
    .with_param_type("time", "DateTime64(3)")?
    .from("events", "")
    .filter([Query::greater_than("time", "2024-01-01 00:00:00"), Query::less_than_equal("value", 100)])
    .build()?;
assert_eq!(
    statement.query,
    "SELECT * FROM `events` WHERE `time` > {param0:DateTime64(3)} AND `value` <= {param1:Int64}"
);
use Utopia\Query\Builder\ClickHouse;
use Utopia\Query\Query;

echo (new ClickHouse())
    ->useNamedBindings()
    ->withParamType('time', 'DateTime64(3)')
    ->from('events')
    ->filter([Query::greaterThan('time', '2024-01-01 00:00:00'), Query::lessThanEqual('value', 100)])
    ->build()->query, "\n";
// SELECT * FROM `events` WHERE `time` > {param0:DateTime64(3)} AND `value` <= {param1:Int64}
Source

pub fn with_param_type( &mut self, column: impl Into<String>, type_name: &str, ) -> Result<&mut Self>

The ClickHouse type of the named placeholders bound against column (others are inferred: Int64, Float64, UInt8, Nullable(String), String).

PHP: withParamType().

Source

pub fn with_param_types<K: Into<String>, V: AsRef<str>>( &mut self, types: impl IntoIterator<Item = (K, V)>, ) -> Result<&mut Self>

Builder::with_param_type for each pair.

PHP: withParamTypes().

Source

pub fn delete_mode(&mut self, mode: DeleteMode) -> &mut Self

Which DELETE form Builder::delete emits.

PHP: deleteMode() (with the mode’s name; see DeleteMode::parse).

Source

pub fn stddev(&mut self, attribute: &str, alias: &str) -> Result<&mut Self>

stddevPop(column) [AS alias]: ClickHouse has no bare STDDEV.

PHP: stddev().

Source

pub fn stddev_pop( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

STDDEV_POP (as an aggregate query).

PHP: stddevPop().

Source

pub fn stddev_samp( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

STDDEV_SAMP (as an aggregate query).

PHP: stddevSamp().

Source

pub fn variance(&mut self, attribute: &str, alias: &str) -> Result<&mut Self>

varPop(column) [AS alias]: ClickHouse has no bare VARIANCE.

PHP: variance().

Source

pub fn var_pop( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

VAR_POP (as an aggregate query).

PHP: varPop().

Source

pub fn var_samp( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

VAR_SAMP (as an aggregate query).

PHP: varSamp().

Source

pub fn quantile( &mut self, level: f64, column: &str, alias: &str, ) -> Result<&mut Self>

quantile(level)(column).

PHP: quantile().

Source

pub fn quantiles( &mut self, levels: &[f64], column: &str, alias: &str, ) -> Result<&mut Self>

quantiles(level, ...)(column); levels must be in [0, 1].

PHP: quantiles().

Source

pub fn quantile_exact( &mut self, level: f64, column: &str, alias: &str, ) -> Result<&mut Self>

quantileExact(level)(column).

PHP: quantileExact().

Source

pub fn median(&mut self, column: &str, alias: &str) -> Result<&mut Self>

median(column).

PHP: median().

Source

pub fn uniq(&mut self, column: &str, alias: &str) -> Result<&mut Self>

uniq(column).

PHP: uniq().

Source

pub fn uniq_exact(&mut self, column: &str, alias: &str) -> Result<&mut Self>

uniqExact(column).

PHP: uniqExact().

Source

pub fn uniq_combined(&mut self, column: &str, alias: &str) -> Result<&mut Self>

uniqCombined(column).

PHP: uniqCombined().

Source

pub fn arg_min( &mut self, value_column: &str, arg_column: &str, alias: &str, ) -> Result<&mut Self>

argMin(value, arg).

PHP: argMin().

Source

pub fn arg_max( &mut self, value_column: &str, arg_column: &str, alias: &str, ) -> Result<&mut Self>

argMax(value, arg).

PHP: argMax().

Source

pub fn top_k(&mut self, k: i64, column: &str, alias: &str) -> Result<&mut Self>

topK(k)(column).

PHP: topK().

Source

pub fn top_k_weighted( &mut self, k: i64, column: &str, weight_column: &str, alias: &str, ) -> Result<&mut Self>

topKWeighted(k)(column, weight).

PHP: topKWeighted().

Source

pub fn any_value(&mut self, column: &str, alias: &str) -> Result<&mut Self>

any(column).

PHP: anyValue().

Source

pub fn any_last_value(&mut self, column: &str, alias: &str) -> Result<&mut Self>

anyLast(column).

PHP: anyLastValue().

Source

pub fn group_uniq_array( &mut self, column: &str, alias: &str, ) -> Result<&mut Self>

groupUniqArray(column).

PHP: groupUniqArray().

Source

pub fn group_array_moving_avg( &mut self, column: &str, alias: &str, ) -> Result<&mut Self>

groupArrayMovingAvg(column).

PHP: groupArrayMovingAvg().

Source

pub fn group_array_moving_sum( &mut self, column: &str, alias: &str, ) -> Result<&mut Self>

groupArrayMovingSum(column).

PHP: groupArrayMovingSum().

Source

pub fn array_join( &mut self, column: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

ARRAY JOIN column [AS alias].

PHP: arrayJoin().

Source

pub fn left_array_join( &mut self, column: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

LEFT ARRAY JOIN column [AS alias].

PHP: leftArrayJoin().

Source

pub fn asof_join<L: AsRef<str>, R: AsRef<str>>( &mut self, table: &str, equi_pairs: impl IntoIterator<Item = (L, R)>, left_inequality: &str, operator: AsofOperator, right_inequality: &str, alias: &str, ) -> Result<&mut Self>

ASOF JOIN table [AS alias] ON l = r AND ... AND left operator right.

PHP: asofJoin().

Source

pub fn asof_left_join<L: AsRef<str>, R: AsRef<str>>( &mut self, table: &str, equi_pairs: impl IntoIterator<Item = (L, R)>, left_inequality: &str, operator: AsofOperator, right_inequality: &str, alias: &str, ) -> Result<&mut Self>

ASOF LEFT JOIN ....

PHP: asofLeftJoin().

Source

pub fn limit_by<S: Into<String>>( &mut self, count: i64, columns: impl IntoIterator<Item = S>, ) -> &mut Self

LIMIT count BY columns.

PHP: limitBy().

Source

pub fn order_with_fill( &mut self, column: &str, direction: &str, from: Option<Value>, to: Option<Value>, step: Option<Value>, ) -> Result<&mut Self>

ORDER BY column ASC|DESC WITH FILL [FROM ?] [TO ?] [STEP ?].

PHP: orderWithFill().

Source§

impl<D: Dialect> Builder<D>

Source

pub fn new() -> Self

An empty builder.

Source

pub fn dialect(&self) -> &D

The dialect’s state.

Source

pub fn class(&self) -> &str

The PHP class messages name: the dialect’s, or the subclass of it given to Builder::set_class.

PHP: static::class.

Source

pub fn set_class(&mut self, class: impl Into<String>) -> &mut Self

Names the PHP class of the builder, when it is a subclass of the dialect’s.

Source

pub fn base_binding_values(&self) -> Vec<Value>

The values bound so far.

PHP: parent::getBindingValues().

Source§

impl<D: Locking> Builder<D>

Source

pub fn for_update(&mut self) -> &mut Self

FOR UPDATE.

PHP: forUpdate().

Source

pub fn for_share(&mut self) -> &mut Self

FOR SHARE.

PHP: forShare().

Source

pub fn for_update_skip_locked(&mut self) -> &mut Self

FOR UPDATE SKIP LOCKED.

PHP: forUpdateSkipLocked().

Source

pub fn for_update_no_wait(&mut self) -> &mut Self

FOR UPDATE NOWAIT.

PHP: forUpdateNoWait().

Source

pub fn for_share_skip_locked(&mut self) -> &mut Self

FOR SHARE SKIP LOCKED.

PHP: forShareSkipLocked().

Source

pub fn for_share_no_wait(&mut self) -> &mut Self

FOR SHARE NOWAIT.

PHP: forShareNoWait().

Source§

impl<D: Transactions> Builder<D>

Source

pub fn begin(&self) -> Statement

BEGIN.

PHP: begin().

Source

pub fn commit(&self) -> Statement

COMMIT.

PHP: commit().

Source

pub fn rollback(&self) -> Statement

ROLLBACK.

PHP: rollback().

Source

pub fn savepoint(&mut self, name: &str) -> Result<Statement>

SAVEPOINT name.

PHP: savepoint().

Source

pub fn release_savepoint(&mut self, name: &str) -> Result<Statement>

RELEASE SAVEPOINT name.

PHP: releaseSavepoint().

Source

pub fn rollback_to_savepoint(&mut self, name: &str) -> Result<Statement>

ROLLBACK TO SAVEPOINT name.

PHP: rollbackToSavepoint().

Source§

impl<D: StatisticalAggregates> Builder<D>

Source

pub fn stddev( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

STDDEV.

PHP: stddev().

Source

pub fn stddev_pop( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

STDDEV_POP.

PHP: stddevPop().

Source

pub fn stddev_samp( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

STDDEV_SAMP.

PHP: stddevSamp().

Source

pub fn variance( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

VARIANCE.

PHP: variance().

Source

pub fn var_pop( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

VAR_POP.

PHP: varPop().

Source

pub fn var_samp( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

VAR_SAMP.

PHP: varSamp().

Source§

impl<D: BitwiseAggregates> Builder<D>

Source

pub fn bit_and( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

BIT_AND.

PHP: bitAnd().

Source

pub fn bit_or( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

BIT_OR.

PHP: bitOr().

Source

pub fn bit_xor( &mut self, attribute: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

BIT_XOR.

PHP: bitXor().

Source§

impl<D: RawSql> Builder<D>

Source

pub fn select_cast( &mut self, column: &str, cast_type: &str, alias: &str, ) -> Result<&mut Self>

CAST(column AS type) [AS alias]; the type must be a type name (words, with an optional argument list).

PHP: selectCast().

Source

pub fn order_by_raw( &mut self, expression: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

A raw ORDER BY expression.

PHP: orderByRaw().

Source

pub fn group_by_raw( &mut self, expression: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

A raw GROUP BY expression.

PHP: groupByRaw().

Source

pub fn having_raw( &mut self, expression: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

A raw HAVING condition.

PHP: havingRaw().

Source

pub fn where_raw( &mut self, expression: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

A raw WHERE condition.

PHP: whereRaw().

Source

pub fn where_column( &mut self, left: &str, operator: &str, right: &str, ) -> Result<&mut Self>

left operator right, both columns.

PHP: whereColumn().

Source

pub fn select_case(&mut self, case: CaseExpression) -> &mut Self

A CASE expression in the select list.

PHP: selectCase().

Source

pub fn set_case( &mut self, column: impl Into<String>, case: CaseExpression, ) -> &mut Self

column = CASE ... in an update.

PHP: setCase().

Source

pub fn set_raw( &mut self, column: impl Into<String>, expression: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

column = expression in an update.

PHP: setRaw().

Source

pub fn conflict_set_raw( &mut self, column: impl Into<String>, expression: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

column = expression in an upsert’s conflict update.

PHP: conflictSetRaw().

Source

pub fn insert_column_expression( &mut self, column: impl Into<String>, expression: impl Into<String>, extra_bindings: impl IntoValues, ) -> &mut Self

The SQL inserted for column instead of ? (ST_GeomFromText(?)), with extra bindings after the value.

PHP: insertColumnExpression().

Source§

impl<D: CrossJoins> Builder<D>

Source

pub fn cross_join( &mut self, table: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

CROSS JOIN table [AS alias].

PHP: crossJoin().

Source

pub fn natural_join( &mut self, table: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

NATURAL JOIN table [AS alias].

PHP: naturalJoin().

Source§

impl<D: FullOuterJoins> Builder<D>

Source

pub fn full_outer_join( &mut self, table: impl Into<String>, left: &str, right: &str, operator: &str, alias: impl Into<String>, ) -> &mut Self

FULL OUTER JOIN table ON left operator right.

PHP: fullOuterJoin().

Source§

impl<D: LateralJoins> Builder<D>

Source

pub fn join_lateral( &mut self, subquery: Box<dyn AnyBuilder>, alias: impl Into<String>, join_type: JoinType, ) -> &mut Self

[LEFT] JOIN LATERAL (subquery) AS alias ON true.

PHP: joinLateral().

Source

pub fn left_join_lateral( &mut self, subquery: Box<dyn AnyBuilder>, alias: impl Into<String>, ) -> &mut Self

LEFT JOIN LATERAL.

PHP: leftJoinLateral().

Source§

impl<D: Rollup> Builder<D>

Source

pub fn with_rollup(&mut self) -> &mut Self

WITH ROLLUP / ROLLUP(...).

PHP: withRollup().

Source§

impl<D: Cube> Builder<D>

Source

pub fn with_cube(&mut self) -> &mut Self

CUBE(...) / WITH CUBE.

PHP: withCube().

Source§

impl<D: Totals> Builder<D>

Source

pub fn with_totals(&mut self) -> &mut Self

WITH TOTALS.

PHP: withTotals().

Source§

impl<D: Hints> Builder<D>

Source

pub fn hint(&mut self, hint: &str) -> Result<&mut Self>

An optimizer hint.

PHP: hint().

Source§

impl<D: ConditionalAggregates> Builder<D>

Source

pub fn count_when( &mut self, condition: &str, alias: &str, bindings: impl IntoValues, ) -> Result<&mut Self>

COUNT(CASE WHEN condition THEN 1 END) [AS alias].

PHP: countWhen().

Source

pub fn sum_when( &mut self, column: &str, condition: &str, alias: &str, bindings: impl IntoValues, ) -> Result<&mut Self>

SUM(CASE WHEN condition THEN column END).

PHP: sumWhen().

Source

pub fn avg_when( &mut self, column: &str, condition: &str, alias: &str, bindings: impl IntoValues, ) -> Result<&mut Self>

AVG(CASE WHEN ...).

PHP: avgWhen().

Source

pub fn min_when( &mut self, column: &str, condition: &str, alias: &str, bindings: impl IntoValues, ) -> Result<&mut Self>

MIN(CASE WHEN ...).

PHP: minWhen().

Source

pub fn max_when( &mut self, column: &str, condition: &str, alias: &str, bindings: impl IntoValues, ) -> Result<&mut Self>

MAX(CASE WHEN ...).

PHP: maxWhen().

Source§

impl<D: StringAggregates> Builder<D>

Source

pub fn group_concat( &mut self, column: &str, separator: &str, alias: &str, order_by: Option<&[String]>, ) -> Result<&mut Self>

The values of column concatenated with separator, optionally ordered (-column descending).

PHP: groupConcat().

Source

pub fn json_array_agg(&mut self, column: &str, alias: &str) -> Result<&mut Self>

A JSON array of column’s values.

PHP: jsonArrayAgg().

Source

pub fn json_object_agg( &mut self, key_column: &str, value_column: &str, alias: &str, ) -> Result<&mut Self>

A JSON object of key and value columns.

PHP: jsonObjectAgg().

Source§

impl<D: Json> Builder<D>

Source

pub fn filter_json_contains( &mut self, attribute: impl Into<String>, value: impl IntoValue, ) -> &mut Self

The JSON column contains value.

PHP: filterJsonContains().

Source

pub fn filter_json_not_contains( &mut self, attribute: impl Into<String>, value: impl IntoValue, ) -> &mut Self

The JSON column does not contain value.

PHP: filterJsonNotContains().

Source

pub fn filter_json_overlaps( &mut self, attribute: impl Into<String>, values: impl IntoValues, ) -> &mut Self

The JSON array column shares an element with values.

PHP: filterJsonOverlaps().

Source

pub fn filter_json_path( &mut self, attribute: impl Into<String>, path: &str, operator: &str, value: impl IntoValue, ) -> &mut Self

The value at path compares to value.

PHP: filterJsonPath().

Source

pub fn set_json_append( &mut self, column: &str, values: impl IntoValues, ) -> Result<&mut Self>

Appends values to the JSON array column (in an update).

PHP: setJsonAppend().

Source

pub fn set_json_prepend( &mut self, column: &str, values: impl IntoValues, ) -> Result<&mut Self>

Prepends values.

PHP: setJsonPrepend().

Source

pub fn set_json_insert( &mut self, column: &str, index: i64, value: impl IntoValue, ) -> Result<&mut Self>

Inserts value at index.

PHP: setJsonInsert().

Source

pub fn set_json_remove( &mut self, column: &str, value: impl IntoValue, ) -> Result<&mut Self>

Removes value.

PHP: setJsonRemove().

Source

pub fn set_json_intersect( &mut self, column: &str, values: impl IntoValues, ) -> Result<&mut Self>

Keeps the elements also in values.

PHP: setJsonIntersect().

Source

pub fn set_json_diff( &mut self, column: &str, values: impl IntoValues, ) -> Result<&mut Self>

Removes the elements in values.

PHP: setJsonDiff().

Source

pub fn set_json_unique(&mut self, column: &str) -> Result<&mut Self>

Removes duplicates.

PHP: setJsonUnique().

Source

pub fn set_json_path( &mut self, column: &str, path: &str, value: impl IntoValue, ) -> Result<&mut Self>

Sets the value at path.

PHP: setJsonPath().

Source§

impl<D: FullTextSearch> Builder<D>

Full-text search on attribute.

PHP: filterSearch().

Source§

impl<D: NegatedFullTextSearch> Builder<D>

Rows not matching a full-text search.

PHP: filterNotSearch().

Source§

impl<D: Upsert> Builder<D>

Source

pub fn upsert(&mut self) -> Result<Statement>

Compiles the upsert (insert, updating the conflict columns on conflict).

PHP: upsert().

Source§

impl<D: UpsertSelect> Builder<D>

Source

pub fn upsert_select(&mut self) -> Result<Statement>

Compiles the upsert from the select source.

PHP: upsertSelect().

Source§

impl<D: InsertOrIgnore> Builder<D>

Source

pub fn insert_or_ignore(&mut self) -> Result<Statement>

Compiles an insert that skips rows that conflict.

PHP: insertOrIgnore().

Source§

impl<D: TableSampling> Builder<D>

Source

pub fn tablesample(&mut self, percent: f64, method: &str) -> Result<&mut Self>

Samples the table.

PHP: tablesample().

Source§

impl<D: Sequences> Builder<D>

Source

pub fn next_val(&mut self, sequence: &str, alias: &str) -> Result<&mut Self>

The next value of sequence.

PHP: nextVal().

Source

pub fn curr_val(&mut self, sequence: &str, alias: &str) -> Result<&mut Self>

The current value of sequence.

PHP: currVal().

Source§

impl<D: Returning> Builder<D>

Source

pub fn returning<S: Into<String>>( &mut self, columns: impl IntoIterator<Item = S>, ) -> &mut Self

The columns returned after inserts, updates and deletes (["*"] for all; empty to stop returning).

PHP: returning().

Source§

impl<D: Spatial> Builder<D>

Source

pub fn filter_distance( &mut self, attribute: impl Into<String>, point: &Array, operator: &str, distance: f64, meters: bool, ) -> Result<&mut Self>

The distance from point ([x, y]) compares to distance with operator (<, >, =, !=; anything else is <), in meters when meters. Fails with Error::Validation unless point is an [x, y] pair of finite numbers.

PHP: filterDistance().

Source

pub fn filter_intersects( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

The geometry column intersects geometry.

PHP: filterIntersects().

Source

pub fn filter_not_intersects( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

Does not intersect.

PHP: filterNotIntersects().

Source

pub fn filter_crosses( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

Crosses.

PHP: filterCrosses().

Source

pub fn filter_not_crosses( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

Does not cross.

PHP: filterNotCrosses().

Source

pub fn filter_overlaps( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

Overlaps.

PHP: filterOverlaps().

Source

pub fn filter_not_overlaps( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

Does not overlap.

PHP: filterNotOverlaps().

Source

pub fn filter_touches( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

Touches.

PHP: filterTouches().

Source

pub fn filter_not_touches( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

Does not touch.

PHP: filterNotTouches().

Source

pub fn filter_covers( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

Covers.

PHP: filterCovers().

Source

pub fn filter_not_covers( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

Does not cover.

PHP: filterNotCovers().

Source

pub fn filter_spatial_equals( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

Spatially equal.

PHP: filterSpatialEquals().

Source

pub fn filter_not_spatial_equals( &mut self, attribute: impl Into<String>, geometry: Array, ) -> &mut Self

Not spatially equal.

PHP: filterNotSpatialEquals().

Source§

impl<D: Dialect> Builder<D>

Source

pub fn set_flavor(&mut self, flavor: Flavor) -> &mut Self

Sets the builder’s Flavor.

Source

pub fn flavor(&self) -> &Flavor

The builder’s Flavor.

Source

pub fn scope(&mut self, scope: Arc<dyn Scope>) -> Result<&mut Self>

Reads collections through scope: from() then takes a collection id.

Fails once from() has read a collection through a scope.

PHP: Scoping::scope().

Source

pub fn is_scoped(&self) -> bool

Whether the builder has a scope.

PHP: Scoping::isScoped().

Source

pub fn bound_collection(&self) -> Option<(&str, &str)>

The collection and alias the builder read through its scope.

Source

pub fn from_table( &mut self, table: impl Into<String>, alias: impl Into<String>, ) -> Result<&mut Self>

Reads the table stored under the name as it is, kept to no tenant.

Fails once from() has read a collection through the scope.

PHP: Scoping::fromTable().

Source

pub fn compile_filters(&mut self, filters: &[Query]) -> Result<Condition>

The filters joined by AND, each compiled as build() compiles the filters of its WHERE, with their bindings in order. The builder’s bindings are replaced by theirs.

PHP: Builder\Filtering::compileFilters() (CompilesFilters).

Source§

impl Builder<MongoDbDialect>

Source

pub fn push(&mut self, field: &str, value: impl IntoValue) -> Result<&mut Self>

Appends value to the array field ($push).

PHP: MongoDB::push().

Source

pub fn pull(&mut self, field: &str, value: impl IntoValue) -> Result<&mut Self>

Removes value (or the elements matching a condition) from the array field ($pull).

PHP: MongoDB::pull().

Source

pub fn add_to_set( &mut self, field: &str, value: impl IntoValue, ) -> Result<&mut Self>

Adds value to the array field unless present ($addToSet).

PHP: MongoDB::addToSet().

Source

pub fn increment( &mut self, field: &str, amount: impl IntoValue, ) -> Result<&mut Self>

Adds amount (an integer or a float) to field ($inc).

PHP: MongoDB::increment().

Source

pub fn unset_fields<S: AsRef<str>>( &mut self, fields: impl IntoIterator<Item = S>, ) -> Result<&mut Self>

Removes the fields from the documents ($unset).

PHP: MongoDB::unsetFields().

Source

pub fn hint(&mut self, hint: impl Into<IndexHint>) -> &mut Self

The index the query uses: a name or a key pattern.

PHP: MongoDB::hint().

Source

pub fn rename(&mut self, old_field: &str, new_field: &str) -> Result<&mut Self>

Renames old_field to new_field ($rename).

PHP: rename() (Feature\MongoDB\FieldUpdates).

Source

pub fn multiply( &mut self, field: &str, factor: impl IntoValue, ) -> Result<&mut Self>

Multiplies field by factor ($mul).

PHP: multiply() (Feature\MongoDB\FieldUpdates).

Source

pub fn pop_first(&mut self, field: &str) -> Result<&mut Self>

Removes the first element of the array field ($pop: -1).

PHP: popFirst() (Feature\MongoDB\FieldUpdates).

Source

pub fn pop_last(&mut self, field: &str) -> Result<&mut Self>

Removes the last element of the array field ($pop: 1).

PHP: popLast() (Feature\MongoDB\FieldUpdates).

Source

pub fn pull_all( &mut self, field: &str, values: impl IntoValues, ) -> Result<&mut Self>

Removes every occurrence of values from the array field ($pullAll).

PHP: pullAll() (Feature\MongoDB\FieldUpdates).

Source

pub fn update_min( &mut self, field: &str, value: impl IntoValue, ) -> Result<&mut Self>

Sets field to value when value is smaller ($min).

PHP: updateMin() (Feature\MongoDB\FieldUpdates).

Source

pub fn update_max( &mut self, field: &str, value: impl IntoValue, ) -> Result<&mut Self>

Sets field to value when value is larger ($max).

PHP: updateMax() (Feature\MongoDB\FieldUpdates).

Source

pub fn current_date( &mut self, field: &str, date_type: &str, ) -> Result<&mut Self>

Sets field to the current date (type is date or timestamp) ($currentDate).

PHP: currentDate() (Feature\MongoDB\FieldUpdates).

Source

pub fn push_each( &mut self, field: &str, values: impl IntoValues, position: Option<i64>, slice: Option<i64>, sort: Option<Array>, ) -> Result<&mut Self>

Appends each of values to the array field, at position, keeping slice elements, sorted by sort ($push with $each).

PHP: pushEach() (Feature\MongoDB\ArrayPushModifiers).

use utopia_query::Query;
use utopia_query::builder::MongoDb;

let statement = MongoDb::new()
    .from("users", "")
    .filter([Query::equal("_id", ["u1"])])
    .push_each("scores", [90, 85], None, Some(-5), None)?
    .increment("visits", 1)?
    .update()?;
assert_eq!(
    statement.query,
    r#"{"collection":"users","operation":"updateMany","filter":{"_id":"?"},"update":{"$push":{"scores":{"$each":["?","?"],"$slice":-5}},"$inc":{"visits":1}}}"#
);
assert_eq!(statement.bindings.len(), 3);
use Utopia\Query\Builder\MongoDB;
use Utopia\Query\Query;

$statement = (new MongoDB())
    ->from('users')
    ->filter([Query::equal('_id', ['u1'])])
    ->pushEach('scores', [90, 85], slice: -5)
    ->increment('visits', 1)
    ->update();
echo $statement->query, "\n";
// {"collection":"users","operation":"updateMany","filter":{"_id":"?"},"update":{"$push":{"scores":{"$each":["?","?"],"$slice":-5}},"$inc":{"visits":1}}}
Source

pub fn array_filter(&mut self, _identifier: &str, condition: Array) -> &mut Self

Adds an arrayFilters condition for a filtered positional update (field.$[identifier]); the identifier is informational and must be the root of the condition’s paths.

PHP: arrayFilter() (Feature\MongoDB\ConditionalArrayUpdates).

Source

pub fn bucket( &mut self, group_by: &str, boundaries: impl IntoValues, default_bucket: Option<&str>, output: Array, ) -> &mut Self

A $bucket stage grouping by group_by between boundaries.

PHP: bucket() (Feature\MongoDB\PipelineStages).

Source

pub fn bucket_auto( &mut self, group_by: &str, buckets: i64, output: Array, ) -> &mut Self

A $bucketAuto stage of buckets buckets over group_by.

PHP: bucketAuto() (Feature\MongoDB\PipelineStages).

Source

pub fn facet<'a, K: AsRef<str>>( &mut self, facets: impl IntoIterator<Item = (K, &'a mut dyn AnyBuilder)>, ) -> Result<&mut Self>

A $facet stage: each named builder (built now) becomes a sub-pipeline.

PHP: facet() (Feature\MongoDB\PipelineStages).

Source

pub fn graph_lookup( &mut self, from: &str, start_with: &str, connect_from_field: &str, connect_to_field: &str, as_field: &str, max_depth: Option<i64>, depth_field: Option<&str>, ) -> &mut Self

A $graphLookup stage: a recursive lookup in from.

PHP: graphLookup() (Feature\MongoDB\PipelineStages).

Source

pub fn merge_into_collection( &mut self, collection: &str, on: Option<Array>, when_matched: Option<Array>, when_not_matched: Option<Array>, ) -> &mut Self

A terminal $merge stage into collection.

PHP: mergeIntoCollection() (Feature\MongoDB\PipelineStages).

Source

pub fn output_to_collection( &mut self, collection: &str, database: Option<&str>, ) -> &mut Self

A terminal $out stage into collection (of database).

PHP: outputToCollection() (Feature\MongoDB\PipelineStages).

Source

pub fn replace_root(&mut self, new_root_expression: &str) -> &mut Self

A $replaceRoot stage with new_root_expression as the new root.

PHP: replaceRoot() (Feature\MongoDB\PipelineStages).

Source

pub fn search(&mut self, definition: Array, index: Option<&str>) -> &mut Self

An Atlas $search stage (first in the pipeline), on index if given.

PHP: search() (Feature\MongoDB\AtlasSearch).

Source

pub fn search_meta( &mut self, definition: Array, index: Option<&str>, ) -> &mut Self

An Atlas $searchMeta stage: the pipeline returns search metadata only.

PHP: searchMeta() (Feature\MongoDB\AtlasSearch).

An Atlas $vectorSearch stage over path.

PHP: vectorSearch() (Feature\MongoDB\AtlasSearch).

Source§

impl<D: MySqlFamily> Builder<D>

Source

pub fn update_join( &mut self, table: impl Into<String>, left: impl Into<String>, right: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

UPDATE table JOIN join [AS alias] ON left = right SET ....

PHP: updateJoin().

Source

pub fn delete_join( &mut self, alias: impl Into<String>, table: impl Into<String>, left: impl Into<String>, right: impl Into<String>, ) -> &mut Self

DELETE alias FROM table AS alias JOIN join ON left = right.

PHP: deleteJoin().

Source

pub fn max_execution_time(&mut self, ms: i64) -> Result<&mut Self>

The MAX_EXECUTION_TIME(ms) hint.

PHP: maxExecutionTime().

Source§

impl Builder<PostgreSqlDialect>

Source

pub fn update_from( &mut self, table: impl Into<String>, alias: impl Into<String>, ) -> &mut Self

UPDATE table SET ... FROM other [AS alias]; keeps a condition set by Builder::update_from_where.

PHP: updateFrom().

Source

pub fn update_from_where( &mut self, condition: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

The condition joining the UPDATE ... FROM table, with its bindings.

PHP: updateFromWhere().

Source

pub fn delete_using( &mut self, table: impl Into<String>, condition: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

DELETE FROM table USING other WHERE condition.

PHP: deleteUsing().

Source

pub fn distinct_on<S: Into<String>>( &mut self, columns: impl IntoIterator<Item = S>, ) -> &mut Self

SELECT DISTINCT ON (columns).

PHP: distinctOn().

Source

pub fn for_update_of(&mut self, table: impl Into<String>) -> &mut Self

FOR UPDATE OF table.

PHP: forUpdateOf().

Source

pub fn for_share_of(&mut self, table: impl Into<String>) -> &mut Self

FOR SHARE OF table.

PHP: forShareOf().

Source

pub fn order_by_vector_distance( &mut self, attribute: impl Into<String>, vector: impl IntoValues, metric: VectorMetric, ) -> &mut Self

Orders by the pgvector distance of attribute to vector (nearest first).

PHP: orderByVectorDistance().

Source

pub fn select_aggregate_filter( &mut self, aggregate: &str, condition: &str, alias: &str, bindings: impl IntoValues, ) -> Result<&mut Self>

aggregate FILTER (WHERE condition) [AS alias] in the select list.

PHP: selectAggregateFilter().

Source

pub fn array_agg(&mut self, column: &str, alias: &str) -> Result<&mut Self>

ARRAY_AGG(column).

PHP: arrayAgg().

Source

pub fn bool_and(&mut self, column: &str, alias: &str) -> Result<&mut Self>

BOOL_AND(column).

PHP: boolAnd().

Source

pub fn bool_or(&mut self, column: &str, alias: &str) -> Result<&mut Self>

BOOL_OR(column).

PHP: boolOr().

Source

pub fn every(&mut self, column: &str, alias: &str) -> Result<&mut Self>

EVERY(column).

PHP: every().

Source

pub fn mode(&mut self, column: &str, alias: &str) -> Result<&mut Self>

MODE() WITHIN GROUP (ORDER BY column).

PHP: mode().

Source

pub fn percentile_cont( &mut self, fraction: f64, order_column: &str, alias: &str, ) -> Result<&mut Self>

PERCENTILE_CONT(fraction) WITHIN GROUP (ORDER BY column).

PHP: percentileCont().

Source

pub fn percentile_disc( &mut self, fraction: f64, order_column: &str, alias: &str, ) -> Result<&mut Self>

PERCENTILE_DISC(fraction) WITHIN GROUP (ORDER BY column).

PHP: percentileDisc().

Source

pub fn merge_into(&mut self, target: impl Into<String>) -> &mut Self

The table a MERGE writes to.

PHP: mergeInto().

Source

pub fn using( &mut self, source: Box<dyn AnyBuilder>, alias: impl Into<String>, ) -> &mut Self

The source query of a MERGE, and its alias.

PHP: using().

Source

pub fn on( &mut self, condition: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

The ON condition of a MERGE, with its bindings.

PHP: on().

Source

pub fn when_matched( &mut self, action: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

WHEN MATCHED THEN action.

PHP: whenMatched().

Source

pub fn when_not_matched( &mut self, action: impl Into<String>, bindings: impl IntoValues, ) -> &mut Self

WHEN NOT MATCHED THEN action.

PHP: whenNotMatched().

Source

pub fn execute_merge(&mut self) -> Result<Statement>

Compiles the MERGE INTO target USING (source) AS alias ON condition WHEN ....

PHP: executeMerge().

Source§

impl<D: Dialect> Builder<D>

Source

pub fn set_overrides(&mut self, overrides: Arc<dyn Overrides>) -> &mut Self

Asks overrides before each Step.

Source

pub fn set_overridden(&mut self, steps: u128) -> &mut Self

Says which steps the overrides take, a bit for each by its place in Step::ALL: the others are not asked about.

Source

pub fn set_owner(&mut self, owner: usize) -> &mut Self

Says whose builder this is, for the overrides and after_build_owned callbacks to read back: state kept beside the builder would cross when two builds interleave on a thread.

Source

pub fn owner(&self) -> usize

The owner Self::set_owner set, or zero: a clone has none.

Source

pub fn base(&mut self, step: Step, arguments: &[Arg<'_>]) -> Result<Ret>

Runs step as the builder itself does, whatever is overridden.

PHP: parent::step(...) in a subclass of the dialect’s builder.

Source

pub fn validate_table(&mut self) -> Result<()>

validateTable(): a subclass’s own when it has one.

Source

pub fn validate_rows(&mut self, operation: &str) -> Result<()>

validateRows().

Source

pub fn validate_and_get_columns(&mut self) -> Result<Vec<ArrayKey>>

validateAndGetColumns().

Source

pub fn add_bindings(&mut self, values: impl IntoIterator<Item = Value>)

addBindings().

Source

pub fn compile_case(&mut self, case: &CaseExpression) -> Result<String>

compileCase().

Source

pub fn compile_insert_body(&mut self) -> Result<(String, Vec<Value>)>

compileInsertBody().

Source

pub fn compile_assignments(&mut self) -> Result<Vec<String>>

compileAssignments().

Source

pub fn compile_where_clauses( &mut self, parts: &mut Vec<String>, grouped: Option<&ParsedQuery>, ) -> Result<()>

compileWhereClauses().

Source

pub fn compile_order_and_limit( &mut self, parts: &mut Vec<String>, grouped: Option<&ParsedQuery>, ) -> Result<()>

compileOrderAndLimit().

Source

pub fn append_returning(&mut self, result: Statement) -> Result<Statement>

appendReturning().

Source

pub fn reset_returning(&mut self)

resetReturning().

Source

pub fn reset_group_by_modifier(&mut self)

resetGroupByModifier().

Trait Implementations§

Source§

impl<D: Dialect> AnyBuilder for Builder<D>

Source§

fn build(&mut self) -> Result<Statement>

Compiles the builder’s statement.
Source§

fn clone_box(&self) -> Box<dyn AnyBuilder>

A boxed copy.
Source§

fn php_class(&self) -> &'static str

The PHP class of the builder (Utopia\Query\Builder\MySQL).
Source§

fn as_any(&self) -> &dyn Any

The builder as Any, to reach its concrete type.
Source§

impl<D: Dialect> Clone for Builder<D>

Source§

fn clone(&self) -> Self

A deep copy (subqueries included); hooks, callbacks and the executor are shared.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<D: Dialect> Compiler for Builder<D>

Source§

fn compile_filter(&mut self, query: &Query) -> Result<String>

A filter (comparisons, spatial, vector, logical, …).
Source§

fn compile_order(&mut self, query: &Query) -> Result<String>

An order (orderAsc, orderDesc, orderRandom).
Source§

fn compile_limit(&mut self, query: &Query) -> Result<String>

A limit.
Source§

fn compile_offset(&mut self, query: &Query) -> Result<String>

An offset.
Source§

fn compile_select(&mut self, query: &Query) -> Result<String>

A selection.
Source§

fn compile_cursor(&mut self, query: &Query) -> Result<String>

A cursor (cursorAfter, cursorBefore).
Source§

fn compile_aggregate(&mut self, query: &Query) -> Result<String>

An aggregate.
Source§

fn compile_group_by(&mut self, query: &Query) -> Result<String>

A group by.
Source§

fn compile_join(&mut self, query: &Query) -> Result<String>

A join.
Source§

impl<D: Dialect> Default for Builder<D>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<D> !RefUnwindSafe for Builder<D>

§

impl<D> !UnwindSafe for Builder<D>

§

impl<D> Forget for Builder<D>

§

impl<D> Freeze for Builder<D>
where Vec<Arc<dyn Fn(&mut Builder<D>) -> Result<(), Error> + Sync + Send>>: Freeze, D: Freeze,

§

impl<D> Move for Builder<D>

§

impl<D> Send for Builder<D>
where Vec<Arc<dyn Fn(&mut Builder<D>) -> Result<(), Error> + Sync + Send>>: Send,

§

impl<D> Sync for Builder<D>
where Vec<Arc<dyn Fn(&mut Builder<D>) -> Result<(), Error> + Sync + Send>>: Sync,

§

impl<D> Unpin for Builder<D>
where D: Unpin, Vec<Arc<dyn Fn(&mut Builder<D>) -> Result<(), Error> + Sync + Send>>: Unpin,

§

impl<D> UnsafeUnpin for Builder<D>
where Vec<Arc<dyn Fn(&mut Builder<D>) -> Result<(), Error> + Sync + Send>>: UnsafeUnpin, D: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.