Skip to main content

QueryBuilder

Struct QueryBuilder 

Source
pub struct QueryBuilder<'a, Schema = (), State = (), Table = (), Marker = (), Row = (), Grouped = ()> {
    pub sql: SQL<'a, PostgresValue<'a>>,
    /* private fields */
}
Expand description

Builds PostgreSQL statements as SQL plus bound parameters, without a connection.

Create one with QueryBuilder::new, then start a statement with select, insert, update, delete or with. Each call returns a builder whose type tracks the clauses added so far, so out-of-order clauses (such as .where() before .from()) do not compile. Call .to_sql() to get the statement. The driver crates wrap this builder to run the query.

Schema is the schema type from #[derive(PostgresSchema)]. The other type parameters are builder state and are inferred.

§Examples

use drizzle::core::expr::eq;

let query = db
    .select((user.id, user.name))
    .from(user)
    .r#where(eq(user.name, "Alice"));

assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."id", "users"."name" FROM "users" WHERE "users"."name" = $1"#
);

Fields§

§sql: SQL<'a, PostgresValue<'a>>

The SQL built so far.

Implementations§

Source§

impl<'a, S, T> QueryBuilder<'a, S, DeleteInitial, T>

Source

pub fn where<E, ScopeProof>( self, condition: E, ) -> DeleteBuilder<'a, S, DeleteWhereSet, T>
where E: ExprSources + Expr<'a, PostgresValue<'a>>, E::Sources: SourcesIn<Cons<T, Nil>, ScopeProof>, E::SQLType: BooleanLike,

Adds a WHERE condition; only matching rows are deleted.

§Compile-time checks

The condition may only use columns of the table being deleted from.

ⓘ
use drizzle::core::expr::eq;

// `posts` is not part of this statement.
let query = db.delete(user).r#where(eq(post.id, 1));
Source

pub fn returning<Columns, ScopeProof>( self, columns: Columns, ) -> DeleteBuilder<'a, S, DeleteReturningSet, T, Scoped<<Columns as IntoSelectTarget>::Marker, Cons<T, Nil>>, <<Columns as IntoSelectTarget>::Marker as ResolveRow<T>>::Row>
where Columns: ExprSources + ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget, Columns::Sources: SourcesIn<Cons<T, Nil>, ScopeProof>, Columns::Marker: ResolveRow<T>,

Adds RETURNING columns, so the statement returns the deleted rows.

Source§

impl<'a, S, T> QueryBuilder<'a, S, DeleteWhereSet, T>

Source

pub fn returning<Columns, ScopeProof>( self, columns: Columns, ) -> DeleteBuilder<'a, S, DeleteReturningSet, T, Scoped<<Columns as IntoSelectTarget>::Marker, Cons<T, Nil>>, <<Columns as IntoSelectTarget>::Marker as ResolveRow<T>>::Row>
where Columns: ExprSources + ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget, Columns::Sources: SourcesIn<Cons<T, Nil>, ScopeProof>, Columns::Marker: ResolveRow<T>,

Adds RETURNING columns after WHERE.

Source§

impl<'a, Schema, Table> QueryBuilder<'a, Schema, InsertInitial, Table>
where Table: PostgresTable<'a>,

Source

pub fn value<T>( self, value: Table::Insert<T>, ) -> InsertBuilder<'a, Schema, InsertValuesSet, Table>

Inserts one row. Shorthand for .values([row]).

§Examples
let query = db.insert(user).value(InsertUser::new("Alice"));
assert_eq!(query.to_sql().sql(), r#"INSERT INTO "users" ("name") VALUES ($1)"#);
Source

pub fn values<I, T>( self, values: I, ) -> InsertBuilder<'a, Schema, InsertValuesSet, Table>
where I: IntoIterator<Item = Table::Insert<T>>,

Inserts the given rows, built with the table’s Insert* model.

Every row has the same model type. A column a row leaves unset gets its database default; when rows set different columns, every row lists the union of the columns, with DEFAULT where it sets none.

§Examples
let query = db
    .insert(user)
    .values([InsertUser::new("Alice"), InsertUser::new("Bob")]);
assert_eq!(
    query.to_sql().sql(),
    r#"INSERT INTO "users" ("name") VALUES ($1), ($2)"#
);
Source

pub fn columns<Columns>( self, columns: Columns, ) -> InsertBuilder<'a, Schema, InsertColumnsSet<Columns::Columns>, Table>
where Columns: InsertTargetColumns<'a, PostgresValue<'a>, Table>,

Sets the target columns, in order, for INSERT ... SELECT.

The list must include every required column (non-null without a default). Continue with select, whose columns must match these in number, order and type.

§Examples
let query = db
    .insert(post)
    .columns((post.author_id, post.title))
    .select(db.select((user.id, user.name)).from(user));
assert_eq!(
    query.to_sql().sql(),
    r#"INSERT INTO "posts" ("author_id", "title") SELECT "users"."id", "users"."name" FROM "users""#
);
Source

pub fn select<Q, R, ScopeProof, AggProof>( self, query: Q, ) -> InsertBuilder<'a, Schema, InsertValuesSet, Table>
where Table: InsertSelectTable, Q: IntoSelectQuery<'a, Schema, R>, Q::Marker: InsertSelectCompatible<'a, PostgresValue<'a>, Table, R> + MarkerScopeValidFor<ScopeProof> + MarkerAggValidFor<Q::Grouped, AggProof>,

Inserts the rows of a SELECT into every insertable column of the table.

The query’s columns must match the table’s insertable columns in number, order, type and nullability, and the query must pass the usual scope and GROUP BY checks; all of this is checked at compile time. To fill only some columns, call columns first.

Source

pub fn select_raw<Q>( self, query: Q, ) -> InsertBuilder<'a, Schema, InsertValuesSet, Table>
where Q: ToSQL<'a, PostgresValue<'a>>,

Inserts the rows of a raw SELECT, with no target column list.

Nothing about the query is checked: not its column count, types, nullability, sources or aggregates. Prefer select.

Source§

impl<'a, Schema, Table, Targets> QueryBuilder<'a, Schema, InsertColumnsSet<Targets>, Table>
where Table: PostgresTable<'a> + InsertSelectTable,

Source

pub fn select<Q, R, RequiredProof, ScopeProof, AggProof>( self, query: Q, ) -> InsertBuilder<'a, Schema, InsertValuesSet, Table>
where Targets: IncludesRequired<Table::RequiredColumns, RequiredProof>, Q: IntoSelectQuery<'a, Schema, R>, Q::Marker: PartialInsertSelectCompatible<'a, PostgresValue<'a>, Targets> + MarkerScopeValidFor<ScopeProof> + MarkerAggValidFor<Q::Grouped, AggProof>,

Inserts the rows of a SELECT into the columns chosen with .columns(...).

The query’s columns must match the target columns in number, order, type and nullability, and the query must pass the usual scope and GROUP BY checks; all of this is checked at compile time.

Source

pub fn select_raw<Q, RequiredProof>( self, query: Q, ) -> InsertBuilder<'a, Schema, InsertValuesSet, Table>
where Targets: IncludesRequired<Table::RequiredColumns, RequiredProof>, Q: ToSQL<'a, PostgresValue<'a>>,

Inserts the rows of a raw SELECT into the chosen target columns.

Only the target list is checked (it must include every required column); the query itself is not. Prefer select.

Source§

impl<'a, S, T> QueryBuilder<'a, S, InsertValuesSet, T>

Source

pub fn on_conflict<C: ConflictTarget<T>>( self, target: C, ) -> OnConflictBuilder<'a, S, T>

Starts ON CONFLICT (columns), handling rows that would violate a unique constraint on the target.

The target is a primary-key column, a unique column, or a unique index (anything implementing ConflictTarget<T>, which the macros generate). Finish with .do_nothing() or .do_update(update_model).

§Examples
fn main() {
use drizzle::postgres::prelude::*;
use drizzle::postgres::builder::QueryBuilder;

#[PostgresTable(name = "users")]
struct User {
    #[column(serial, primary)]
    id: i32,
    name: String,
    #[column(unique)]
    email: Option<String>,
}

#[PostgresIndex(unique)]
struct UserEmailIdx(User::email);

#[derive(PostgresSchema)]
struct Schema {
    user: User,
    user_email_idx: UserEmailIdx,
}

let builder = QueryBuilder::new::<Schema>();
let schema = Schema::new();
let user = schema.user;

// Target a specific column
builder.insert(user).values([InsertUser::new("Alice")])
    .on_conflict(user.id).do_nothing();

// DO UPDATE with new values
let query = builder.insert(user).values([InsertUser::new("Alice")])
    .on_conflict(user.email).do_update(UpdateUser::default().with_name("updated"));
assert_eq!(
    query.to_sql().sql(),
    r#"INSERT INTO "users" ("name") VALUES ($1) ON CONFLICT ("email") DO UPDATE SET "name" = $2"#
);

// Target a unique index
builder.insert(user).values([InsertUser::new("Alice")])
    .on_conflict(schema.user_email_idx).do_nothing();
}
Source

pub fn on_conflict_on_constraint<C: NamedConstraint<T>>( self, target: C, ) -> OnConflictBuilder<'a, S, T>

Starts ON CONFLICT ON CONSTRAINT name, naming the unique constraint to handle.

The target is a unique column or a named unique constraint (anything implementing NamedConstraint<T>, which the macros generate). A standalone unique index is not a constraint, so PostgreSQL rejects it here; use on_conflict for indexes. Finish with .do_nothing() or .do_update(update_model).

§Examples
fn main() {
use drizzle::postgres::prelude::*;
use drizzle::postgres::builder::QueryBuilder;

#[PostgresTable(name = "users")]
struct User {
    #[column(serial, primary)]
    id: i32,
    name: String,
    #[column(unique)]
    email: Option<String>,
}

#[derive(PostgresSchema)]
struct Schema {
    user: User,
}

let builder = QueryBuilder::new::<Schema>();
let schema = Schema::new();

let user = schema.user;
builder.insert(user).values([InsertUser::new("Alice")])
    .on_conflict_on_constraint(user.email).do_nothing();
}
Source

pub fn on_conflict_do_nothing( self, ) -> InsertBuilder<'a, S, InsertOnConflictSet, T>

Adds ON CONFLICT DO NOTHING with no target: rows that violate any unique or exclusion constraint are skipped.

Source

pub fn returning<Columns, ScopeProof>( self, columns: Columns, ) -> InsertBuilder<'a, S, InsertReturningSet, T, Scoped<<Columns as IntoSelectTarget>::Marker, Cons<T, Nil>>, <<Columns as IntoSelectTarget>::Marker as ResolveRow<T>>::Row>
where Columns: ExprSources + ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget, Columns::Sources: SourcesIn<Cons<T, Nil>, ScopeProof>, Columns::Marker: ResolveRow<T>,

Adds RETURNING columns, so the statement returns the inserted rows.

Pass a column, a tuple of columns, or () for all columns. Only columns of the target table are allowed.

§Examples
let query = db
    .insert(user)
    .values([InsertUser::new("Alice")])
    .returning((user.id, user.name));
assert_eq!(
    query.to_sql().sql(),
    r#"INSERT INTO "users" ("name") VALUES ($1) RETURNING "users"."id", "users"."name""#
);
Source§

impl<'a, S, T> QueryBuilder<'a, S, InsertOnConflictSet, T>

Source

pub fn returning<Columns, ScopeProof>( self, columns: Columns, ) -> InsertBuilder<'a, S, InsertReturningSet, T, Scoped<<Columns as IntoSelectTarget>::Marker, Cons<T, Nil>>, <<Columns as IntoSelectTarget>::Marker as ResolveRow<T>>::Row>
where Columns: ExprSources + ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget, Columns::Sources: SourcesIn<Cons<T, Nil>, ScopeProof>, Columns::Marker: ResolveRow<T>,

Adds RETURNING columns after the ON CONFLICT clause.

Rows skipped by DO NOTHING are not returned.

Source§

impl<'a, S, T> QueryBuilder<'a, S, InsertDoUpdateSet, T>

Source

pub fn where<E, ScopeProof>( self, condition: E, ) -> InsertBuilder<'a, S, InsertOnConflictSet, T>
where E: ExprSources + Expr<'a, PostgresValue<'a>>, E::Sources: SourcesIn<Cons<T, Nil>, ScopeProof>, E::SQLType: BooleanLike,

Adds a WHERE condition to DO UPDATE: conflicting rows are updated only when it holds.

Renders ON CONFLICT (...) DO UPDATE SET ... WHERE condition. The condition may only use columns of the target table.

Source

pub fn returning<Columns, ScopeProof>( self, columns: Columns, ) -> InsertBuilder<'a, S, InsertReturningSet, T, Scoped<<Columns as IntoSelectTarget>::Marker, Cons<T, Nil>>, <<Columns as IntoSelectTarget>::Marker as ResolveRow<T>>::Row>
where Columns: ExprSources + ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget, Columns::Sources: SourcesIn<Cons<T, Nil>, ScopeProof>, Columns::Marker: ResolveRow<T>,

Adds RETURNING columns after DO UPDATE SET.

Source§

impl<'a, S, M> QueryBuilder<'a, S, SelectInitial, (), M>

Source

pub fn from<T>( self, query: T, ) -> SelectBuilder<'a, S, SelectFromSet, T, FromMarker<M, T>, <M as ResolveRow<T>>::Row>
where T: ToSQL<'a, PostgresValue<'a>> + ScopeEntry, M: ResolveRow<T>,

Sets the FROM source: a table, a view, an aliased table, a derived table (.alias(...)), or a CTE.

§Examples
let query = db.select(()).from(user);
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."id", "users"."name", "users"."email" FROM "users""#
);
Source§

impl<'a, S, State, T, M, R, G> QueryBuilder<'a, S, State, T, M, R, G>
where State: ClauseAllowed<Join>,

Source

pub fn join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, InnerJoin, J::OnSources>>::Marker, <M as JoinStep<R, J::JoinedTable, InnerJoin, J::OnSources>>::Row, G>
where M: JoinStep<R, J::JoinedTable, InnerJoin, J::OnSources>,

Adds an inner JOIN ... ON ....

Pass (source, condition), or a bare table to join on its foreign key to the previous table. The tables the condition reads are checked against the query’s scope at compile time, where the query is run (.all(), .get(), .rows()). Other join kinds have their own methods: left_join, right_join, full_join, inner_join, their _outer forms, natural_* joins, *_join_using, and the *_lateral joins.

§Examples
use drizzle::core::expr::eq;

let query = db
    .select((user.name, post.title))
    .from(user)
    .join((post, eq(post.author_id, user.id)));
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."name", "posts"."title" FROM "users" JOIN "posts" ON "posts"."author_id" = "users"."id""#
);
Source

pub fn natural_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, InnerJoin>>::Marker, <M as JoinStep<R, J::JoinedTable, InnerJoin>>::Row, G>
where M: JoinStep<R, J::JoinedTable, InnerJoin>,

Adds a NATURAL join of the kind named by the method.

The database joins on every column name both sides share, so this takes only a table or other source, with no ON condition.

Source

pub fn natural_left_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, LeftJoin>>::Marker, <M as JoinStep<R, J::JoinedTable, LeftJoin>>::Row, G>
where M: JoinStep<R, J::JoinedTable, LeftJoin>,

Adds a NATURAL join of the kind named by the method.

The database joins on every column name both sides share, so this takes only a table or other source, with no ON condition.

Source

pub fn left_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, LeftJoin, J::OnSources>>::Marker, <M as JoinStep<R, J::JoinedTable, LeftJoin, J::OnSources>>::Row, G>
where M: JoinStep<R, J::JoinedTable, LeftJoin, J::OnSources>,

Adds a join of the kind named by the method, with an ON condition.

Pass (source, condition), or a bare table to join on its foreign key to the previous table. An outer join makes the columns of its nullable side (the joined source for LEFT, the earlier sources for RIGHT, both for FULL) decode as Option.

Source

pub fn left_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, LeftJoin, J::OnSources>>::Marker, <M as JoinStep<R, J::JoinedTable, LeftJoin, J::OnSources>>::Row, G>
where M: JoinStep<R, J::JoinedTable, LeftJoin, J::OnSources>,

Adds a join of the kind named by the method, with an ON condition.

Pass (source, condition), or a bare table to join on its foreign key to the previous table. An outer join makes the columns of its nullable side (the joined source for LEFT, the earlier sources for RIGHT, both for FULL) decode as Option.

Source

pub fn natural_left_outer_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, LeftJoin>>::Marker, <M as JoinStep<R, J::JoinedTable, LeftJoin>>::Row, G>
where M: JoinStep<R, J::JoinedTable, LeftJoin>,

Adds a NATURAL join of the kind named by the method.

The database joins on every column name both sides share, so this takes only a table or other source, with no ON condition.

Source

pub fn natural_right_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, RightJoin>>::Marker, <M as JoinStep<R, J::JoinedTable, RightJoin>>::Row, G>
where M: JoinStep<R, J::JoinedTable, RightJoin>,

Adds a NATURAL join of the kind named by the method.

The database joins on every column name both sides share, so this takes only a table or other source, with no ON condition.

Source

pub fn right_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, RightJoin, J::OnSources>>::Marker, <M as JoinStep<R, J::JoinedTable, RightJoin, J::OnSources>>::Row, G>
where M: JoinStep<R, J::JoinedTable, RightJoin, J::OnSources>,

Adds a join of the kind named by the method, with an ON condition.

Pass (source, condition), or a bare table to join on its foreign key to the previous table. An outer join makes the columns of its nullable side (the joined source for LEFT, the earlier sources for RIGHT, both for FULL) decode as Option.

Source

pub fn right_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, RightJoin, J::OnSources>>::Marker, <M as JoinStep<R, J::JoinedTable, RightJoin, J::OnSources>>::Row, G>
where M: JoinStep<R, J::JoinedTable, RightJoin, J::OnSources>,

Adds a join of the kind named by the method, with an ON condition.

Pass (source, condition), or a bare table to join on its foreign key to the previous table. An outer join makes the columns of its nullable side (the joined source for LEFT, the earlier sources for RIGHT, both for FULL) decode as Option.

Source

pub fn natural_right_outer_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, RightJoin>>::Marker, <M as JoinStep<R, J::JoinedTable, RightJoin>>::Row, G>
where M: JoinStep<R, J::JoinedTable, RightJoin>,

Adds a NATURAL join of the kind named by the method.

The database joins on every column name both sides share, so this takes only a table or other source, with no ON condition.

Source

pub fn natural_full_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, FullJoin>>::Marker, <M as JoinStep<R, J::JoinedTable, FullJoin>>::Row, G>
where M: JoinStep<R, J::JoinedTable, FullJoin>,

Adds a NATURAL join of the kind named by the method.

The database joins on every column name both sides share, so this takes only a table or other source, with no ON condition.

Source

pub fn full_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, FullJoin, J::OnSources>>::Marker, <M as JoinStep<R, J::JoinedTable, FullJoin, J::OnSources>>::Row, G>
where M: JoinStep<R, J::JoinedTable, FullJoin, J::OnSources>,

Adds a join of the kind named by the method, with an ON condition.

Pass (source, condition), or a bare table to join on its foreign key to the previous table. An outer join makes the columns of its nullable side (the joined source for LEFT, the earlier sources for RIGHT, both for FULL) decode as Option.

Source

pub fn full_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, FullJoin, J::OnSources>>::Marker, <M as JoinStep<R, J::JoinedTable, FullJoin, J::OnSources>>::Row, G>
where M: JoinStep<R, J::JoinedTable, FullJoin, J::OnSources>,

Adds a join of the kind named by the method, with an ON condition.

Pass (source, condition), or a bare table to join on its foreign key to the previous table. An outer join makes the columns of its nullable side (the joined source for LEFT, the earlier sources for RIGHT, both for FULL) decode as Option.

Source

pub fn natural_full_outer_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, FullJoin>>::Marker, <M as JoinStep<R, J::JoinedTable, FullJoin>>::Row, G>
where M: JoinStep<R, J::JoinedTable, FullJoin>,

Adds a NATURAL join of the kind named by the method.

The database joins on every column name both sides share, so this takes only a table or other source, with no ON condition.

Source

pub fn inner_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, InnerJoin, J::OnSources>>::Marker, <M as JoinStep<R, J::JoinedTable, InnerJoin, J::OnSources>>::Row, G>
where M: JoinStep<R, J::JoinedTable, InnerJoin, J::OnSources>,

Adds a join of the kind named by the method, with an ON condition.

Pass (source, condition), or a bare table to join on its foreign key to the previous table. An outer join makes the columns of its nullable side (the joined source for LEFT, the earlier sources for RIGHT, both for FULL) decode as Option.

Source

pub fn left_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as JoinStep<R, U, LeftJoin>>::Marker, <M as JoinStep<R, U, LeftJoin>>::Row, G>
where M: JoinStep<R, U, LeftJoin>,

Adds a join of the kind named by the method, with USING (columns): joins on equal values of same-named columns.

Pass bare column names, such as SQL::ident("id"); see join_using.

Source

pub fn left_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as JoinStep<R, U, LeftJoin>>::Marker, <M as JoinStep<R, U, LeftJoin>>::Row, G>
where M: JoinStep<R, U, LeftJoin>,

Adds a join of the kind named by the method, with USING (columns): joins on equal values of same-named columns.

Pass bare column names, such as SQL::ident("id"); see join_using.

Source

pub fn right_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as JoinStep<R, U, RightJoin>>::Marker, <M as JoinStep<R, U, RightJoin>>::Row, G>
where M: JoinStep<R, U, RightJoin>,

Adds a join of the kind named by the method, with USING (columns): joins on equal values of same-named columns.

Pass bare column names, such as SQL::ident("id"); see join_using.

Source

pub fn right_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as JoinStep<R, U, RightJoin>>::Marker, <M as JoinStep<R, U, RightJoin>>::Row, G>
where M: JoinStep<R, U, RightJoin>,

Adds a join of the kind named by the method, with USING (columns): joins on equal values of same-named columns.

Pass bare column names, such as SQL::ident("id"); see join_using.

Source

pub fn full_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as JoinStep<R, U, FullJoin>>::Marker, <M as JoinStep<R, U, FullJoin>>::Row, G>
where M: JoinStep<R, U, FullJoin>,

Adds a join of the kind named by the method, with USING (columns): joins on equal values of same-named columns.

Pass bare column names, such as SQL::ident("id"); see join_using.

Source

pub fn full_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as JoinStep<R, U, FullJoin>>::Marker, <M as JoinStep<R, U, FullJoin>>::Row, G>
where M: JoinStep<R, U, FullJoin>,

Adds a join of the kind named by the method, with USING (columns): joins on equal values of same-named columns.

Pass bare column names, such as SQL::ident("id"); see join_using.

Source

pub fn inner_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as JoinStep<R, U, InnerJoin>>::Marker, <M as JoinStep<R, U, InnerJoin>>::Row, G>
where M: JoinStep<R, U, InnerJoin>,

Adds a join of the kind named by the method, with USING (columns): joins on equal values of same-named columns.

Pass bare column names, such as SQL::ident("id"); see join_using.

Source

pub fn join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as JoinStep<R, U, InnerJoin>>::Marker, <M as JoinStep<R, U, InnerJoin>>::Row, G>
where M: JoinStep<R, U, InnerJoin>,

Adds JOIN table USING (columns), joining on equal values of same-named columns.

columns is rendered as given, and PostgreSQL requires bare names here: pass SQL::ident("id"), not a table column, which renders qualified.

Source

pub fn cross_join<Arg: CrossJoinArg<'a, T>>( self, arg: Arg, ) -> SelectBuilder<'a, S, SelectJoinSet, Arg::JoinedTable, <M as JoinStep<R, Arg::JoinedTable, InnerJoin, Arg::OnSources>>::Marker, <M as JoinStep<R, Arg::JoinedTable, InnerJoin, Arg::OnSources>>::Row, G>
where M: JoinStep<R, Arg::JoinedTable, InnerJoin, Arg::OnSources>,

Adds a CROSS JOIN: every row of the left side paired with every row of source.

For backwards compatibility, (source, condition) is also accepted and renders the equivalent INNER JOIN ... ON ....

§Examples
let query = db.select((user.name, post.title)).from(user).cross_join(post);
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."name", "posts"."title" FROM "users" CROSS JOIN "posts""#
);
Source

pub fn inner_join_lateral<J>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, Lateral<InnerJoin>, J::OnSources>>::Marker, <M as JoinStep<R, J::JoinedTable, Lateral<InnerJoin>, J::OnSources>>::Row, G>
where J: LateralArg<'a, PostgresValue<'a>>, M: JoinStep<R, J::JoinedTable, Lateral<InnerJoin>, J::OnSources>,

Adds INNER JOIN LATERAL (subquery) AS alias ON condition.

A lateral subquery can refer to columns of the sources joined before it. Pass (derived_table, condition), where the derived table comes from .alias(tag) on a SELECT.

Source

pub fn left_join_lateral<J, SelectionProof>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as JoinStep<R, J::JoinedTable, Lateral<LeftJoin>, J::OnSources>>::Marker, <M as JoinStep<R, J::JoinedTable, Lateral<LeftJoin>, J::OnSources>>::Row, G>
where J: LateralArg<'a, PostgresValue<'a>>, M: JoinStep<R, J::JoinedTable, Lateral<LeftJoin>, J::OnSources> + LeftLateralSelection<SelectionProof>,

Adds LEFT JOIN LATERAL (subquery) AS alias ON condition.

Like inner_join_lateral, but keeps left rows with no match. With select(()) the lateral source decodes as an Option of its row; an explicit column list may only read sources joined before the lateral join.

Source

pub fn cross_join_lateral<Source>( self, source: Source, ) -> SelectBuilder<'a, S, SelectJoinSet, Source::JoinedTable, <M as JoinStep<R, Source::JoinedTable, Lateral<InnerJoin>>>::Marker, <M as JoinStep<R, Source::JoinedTable, Lateral<InnerJoin>>>::Row, G>
where Source: LateralSource<'a, PostgresValue<'a>>, M: JoinStep<R, Source::JoinedTable, Lateral<InnerJoin>>,

Adds CROSS JOIN LATERAL (subquery) AS alias, with no ON condition.

The subquery runs once per left row and can refer to its columns.

Source§

impl<'a, S, State, T, M, R, G> QueryBuilder<'a, S, State, T, M, R, G>
where State: SelectClause<Where>,

Source

pub fn where<E>( self, condition: E, ) -> SelectBuilder<'a, S, SelectWhereSet, T, <M as HasScope>::With<E::Sources>, R, G>
where M: HasScope, E: Expr<'a, PostgresValue<'a>>, E::SQLType: BooleanLike,

Adds a WHERE condition.

The condition must be boolean, such as eq(...), and(...) or a boolean column. Every column it uses must come from a source in FROM or a join. The compiler checks this where the query is run (.all(), .get(), .rows()): a column of another table fails there with “X is not in this query’s FROM/JOIN scope”.

§Examples
use drizzle::core::expr::{and, eq, gt};

let query = db
    .select(user.id)
    .from(user)
    .r#where(and(eq(user.name, "Alice"), gt(user.id, 10)));
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."id" FROM "users" WHERE ("users"."name" = $1 AND "users"."id" > $2)"#
);
Source§

impl<'a, S, State, T, M, R, G> QueryBuilder<'a, S, State, T, M, R, G>
where State: ClauseAllowed<GroupBy>,

Source

pub fn group_by<Gr>( self, columns: Gr, ) -> SelectBuilder<'a, S, SelectGroupSet, T, <M as HasScope>::With<Gr::Sources>, R, Gr::Columns>
where M: HasScope, Gr: IntoGroupBy<'a, PostgresValue<'a>>,

Adds a GROUP BY list: one expression or a tuple of them.

Non-aggregate columns in the SELECT list must appear in the GROUP BY list, with one exception: grouping by a table’s single-column primary key determines the whole row, so any column of that table may be selected without being listed (PostgreSQL allows this too).

§Examples
use drizzle::core::expr::{count, gt};

let query = db
    .select((post.author_id, count(post.id)))
    .from(post)
    .group_by(post.author_id)
    .having(gt(count(post.id), 5));
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "posts"."author_id", COUNT ("posts"."id") FROM "posts" GROUP BY "posts"."author_id" HAVING COUNT ("posts"."id")> $1"#
);
Source§

impl<'a, S, State, T, M, R, G> QueryBuilder<'a, S, State, T, M, R, G>
where State: ClauseAllowed<Having>,

Source

pub fn having<E>( self, condition: E, ) -> SelectBuilder<'a, S, SelectGroupSet, T, <M as HasScope>::With<E::Sources>, R, G>
where M: HasScope, E: Expr<'a, PostgresValue<'a>>, E::SQLType: BooleanLike,

Adds a HAVING condition, which filters groups after GROUP BY.

See group_by for an example.

Source§

impl<'a, S, State, T, M, R, G> QueryBuilder<'a, S, State, T, M, R, G>
where State: SelectClause<OrderBy>,

Source

pub fn order_by<TOrderBy>( self, expressions: TOrderBy, ) -> SelectBuilder<'a, S, SelectOrderSet, T, <M as HasScope>::With<TOrderBy::Sources>, R, G>
where M: HasScope, TOrderBy: ToSQL<'a, PostgresValue<'a>> + ExprSources,

Adds ORDER BY.

Pass a column (ascending by default), asc(col) / desc(col), or a tuple of them. An array also works when every term reads the same table; terms over different tables go in a tuple.

§Examples
use drizzle::core::{asc, desc};

let query = db
    .select(user.name)
    .from(user)
    .order_by([asc(user.name), desc(user.id)]);
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."name" FROM "users" ORDER BY "users"."name" ASC, "users"."id" DESC"#
);
Source§

impl<'a, S, T, M, R, G> QueryBuilder<'a, S, SelectSetOpSet, T, M, R, G>

Source

pub fn order_by<TOrderBy>( self, expressions: TOrderBy, ) -> SelectBuilder<'a, S, SelectOrderSet, T, M, R, G>
where TOrderBy: ToSQL<'a, PostgresValue<'a>>,

Adds ORDER BY to a compound (UNION / INTERSECT / EXCEPT) query.

The terms sort the combined output, so column references render unqualified ("name", not "users"."name"), as PostgreSQL requires.

§Examples
let query = db
    .select(user.name)
    .from(user)
    .union_all(db.select(post.title).from(post))
    .order_by(user.name);
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."name" FROM "users" UNION ALL SELECT "posts"."title" FROM "posts" ORDER BY "name""#
);
Source§

impl<'a, S, State, T, M, R, G> QueryBuilder<'a, S, State, T, M, R, G>
where State: ClauseAllowed<Limit>,

Source

pub fn limit<P>( self, limit: P, ) -> SelectBuilder<'a, S, SelectLimitSet, T, M, R, G>
where P: PaginationArg<'a, PostgresValue<'a>>,

Adds LIMIT n, returning at most n rows.

n is a non-negative integer (bound as a parameter) or a placeholder.

§Examples
let query = db.select(user.id).from(user).limit(5);
assert_eq!(query.to_sql().sql(), r#"SELECT "users"."id" FROM "users" LIMIT $1"#);
§Panics

Panics when a signed numeric argument is negative or a numeric value does not fit in usize.

Source§

impl<'a, S, State, T, M, R, G> QueryBuilder<'a, S, State, T, M, R, G>
where State: ClauseAllowed<Offset>,

Source

pub fn offset<P>( self, offset: P, ) -> SelectBuilder<'a, S, SelectOffsetSet, T, M, R, G>
where P: PaginationArg<'a, PostgresValue<'a>>,

Adds OFFSET n, skipping the first n rows.

n is a non-negative integer (bound as a parameter) or a placeholder.

§Examples
let query = db.select(user.id).from(user).limit(10).offset(20);
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."id" FROM "users" LIMIT $1 OFFSET $2"#
);
§Panics

Panics when a signed numeric argument is negative or a numeric value does not fit in usize.

Source§

impl<'a, S, State, T, M, R, G> QueryBuilder<'a, S, State, T, M, R, G>
where State: ClauseAllowed<Source>,

Source

pub fn alias<Tag, AggProof>( self, _tag: Tag, ) -> Derived<'a, PostgresValue<'a>, Tag, <M as DerivedSelection<'a, PostgresValue<'a>, PostgresSchemaType, T>>::Projection, Self>
where Tag: Tag, M: DerivedSelection<'a, PostgresValue<'a>, PostgresSchemaType, T> + MarkerAggValidFor<G, AggProof>, <M as DerivedSelection<'a, PostgresValue<'a>, PostgresSchemaType, T>>::Projection: DerivedProjection<Tag>,

Turns this SELECT into a derived table, (SELECT ...) AS tag.

The result can be used in .from(...) or a lateral join; read its columns with .fields().

§Panics

Panics when the projection contains duplicate output names. Name a computed expression with drizzle_core::expr::AliasExt::named to make each output unique.

Source§

impl<'a, S, State, T, M, R, G> QueryBuilder<'a, S, State, T, M, R, G>

Source

pub fn into_cte<Tag: Tag + 'static>( self, ) -> CTEView<'a, <T as SQLTable<'a, PostgresSchemaType, PostgresValue<'a>>>::Aliased<Tag>, Self>

Turns this SELECT into a common table expression named Tag::NAME.

The result has the same columns as the FROM table. Pass it to QueryBuilder::with, and read its columns through its .table field; see QueryBuilder::with for an example.

Source§

impl<'a, S, State, T, M, R, G> QueryBuilder<'a, S, State, T, M, R, G>
where State: ClauseAllowed<Compound>,

Source

pub fn union<M2>( self, other: impl IntoSelect<'a, S, M2, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, <M as SetOperand<M2>>::Combined, R, G>
where M: SetOperand<M2>,

Combines this query with other using UNION, which drops duplicate rows.

Both queries must decode to the same row type, which the compiler checks. The union_all, intersect, intersect_all, except and except_all methods work the same way.

§Examples
let query = db
    .select(user.name)
    .from(user)
    .union(db.select(post.title).from(post));
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."name" FROM "users" UNION SELECT "posts"."title" FROM "posts""#
);
Source

pub fn union_all<M2>( self, other: impl IntoSelect<'a, S, M2, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, <M as SetOperand<M2>>::Combined, R, G>
where M: SetOperand<M2>,

Combines this query with other using UNION ALL, which keeps duplicates.

Source

pub fn intersect<M2>( self, other: impl IntoSelect<'a, S, M2, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, <M as SetOperand<M2>>::Combined, R, G>
where M: SetOperand<M2>,

Keeps the rows present in both queries (INTERSECT), without duplicates.

Source

pub fn intersect_all<M2>( self, other: impl IntoSelect<'a, S, M2, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, <M as SetOperand<M2>>::Combined, R, G>
where M: SetOperand<M2>,

Keeps the rows present in both queries (INTERSECT ALL), with duplicates.

Source

pub fn except<M2>( self, other: impl IntoSelect<'a, S, M2, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, <M as SetOperand<M2>>::Combined, R, G>
where M: SetOperand<M2>,

Keeps the rows of this query that are not in other (EXCEPT), without duplicates.

Source

pub fn except_all<M2>( self, other: impl IntoSelect<'a, S, M2, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, <M as SetOperand<M2>>::Combined, R, G>
where M: SetOperand<M2>,

Keeps the rows of this query that are not in other (EXCEPT ALL), with duplicates.

Source§

impl<'a, S, State, T, M, R, G> QueryBuilder<'a, S, State, T, M, R, G>
where State: ClauseAllowed<Simple>,

Source

pub fn for_update(self) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR UPDATE, locking the selected rows against updates and deletes by other transactions until this one ends.

Follow with nowait or skip_locked to change what happens when a row is already locked.

§Examples
let query = db.select(user.id).from(user).for_update().skip_locked();
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."id" FROM "users" FOR UPDATE SKIP LOCKED"#
);
Source

pub fn for_share(self) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR SHARE: other transactions can still read and share-lock the rows, but cannot update or delete them.

Source

pub fn for_no_key_update(self) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR NO KEY UPDATE: like FOR UPDATE, but does not block FOR KEY SHARE locks (for example, foreign-key checks).

Source

pub fn for_key_share(self) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR KEY SHARE: blocks deletes and key changes, but allows other updates.

Source

pub fn for_update_of<U: PostgresTable<'a>>( self, table: U, ) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR UPDATE OF table, locking rows of that table only.

§Examples
use drizzle::core::expr::eq;

let query = db
    .select((user.id, post.id))
    .from(user)
    .join((post, eq(post.author_id, user.id)))
    .for_update_of(user);
assert!(query.to_sql().sql().ends_with(r#"FOR UPDATE OF "users""#));
Source

pub fn for_share_of<U: PostgresTable<'a>>( self, table: U, ) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR SHARE OF table, locking rows of that table only.

Source§

impl<S, T, M, R, G> QueryBuilder<'_, S, SelectForSet, T, M, R, G>

Source

pub fn nowait(self) -> Self

Adds NOWAIT: the query fails at once instead of waiting when a row is already locked.

Source

pub fn skip_locked(self) -> Self

Adds SKIP LOCKED: rows already locked by another transaction are left out of the result instead of waited for.

Source§

impl<'a, Schema, Table> QueryBuilder<'a, Schema, UpdateInitial, Table>
where Table: SQLTable<'a, PostgresSchemaType, PostgresValue<'a>>,

Source

pub fn set( self, values: Table::Update, ) -> UpdateBuilder<'a, Schema, UpdateSetClauseSet, Table>

Sets the new column values from the table’s Update* model.

Only the fields set on the model (with .with_*) are written.

Source§

impl<'a, S, T> QueryBuilder<'a, S, UpdateSetClauseSet, T>

Source

pub fn from<F>( self, source: F, ) -> UpdateBuilder<'a, S, UpdateFromSet, T, Cons<F, Nil>>
where F: ToSQL<'a, PostgresValue<'a>> + ScopeEntry,

Adds FROM source, making another table’s columns available to WHERE and RETURNING.

§Examples
use drizzle::core::expr::eq;

let query = db
    .update(user)
    .set(UpdateUser::default().with_name("Author"))
    .from(post)
    .r#where(eq(post.author_id, user.id));
assert_eq!(
    query.to_sql().sql(),
    r#"UPDATE "users" SET "name" = $1 FROM "posts" WHERE "posts"."author_id" = "users"."id""#
);
Source

pub fn where<E, ScopeProof>( self, condition: E, ) -> UpdateBuilder<'a, S, UpdateWhereSet, T>
where E: ExprSources + Expr<'a, PostgresValue<'a>>, E::Sources: SourcesIn<Cons<T, Nil>, ScopeProof>, E::SQLType: BooleanLike,

Adds a WHERE condition; only matching rows are updated.

The condition may only use columns of the updated table; to use other tables, add from first.

Source

pub fn returning<Columns, ScopeProof>( self, columns: Columns, ) -> UpdateBuilder<'a, S, UpdateReturningSet, T, Scoped<<Columns as IntoSelectTarget>::Marker, Cons<T, Nil>>, <<Columns as IntoSelectTarget>::Marker as ResolveRow<T>>::Row>
where Columns: ExprSources + ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget, Columns::Sources: SourcesIn<Cons<T, Nil>, ScopeProof>, Columns::Marker: ResolveRow<T>,

Adds RETURNING columns, so the statement returns the updated rows.

Source§

impl<'a, S, T, M> QueryBuilder<'a, S, UpdateFromSet, T, M>

Source

pub fn where<E, ScopeProof>( self, condition: E, ) -> UpdateBuilder<'a, S, UpdateWhereSet, T, M>
where E: ExprSources + Expr<'a, PostgresValue<'a>>, E::Sources: SourcesIn<Cons<T, M>, ScopeProof>, E::SQLType: BooleanLike,

Adds a WHERE condition, which may use the updated table and the FROM source.

Source

pub fn returning<Columns, ScopeProof>( self, columns: Columns, ) -> UpdateBuilder<'a, S, UpdateReturningSet, T, Scoped<<Columns as IntoSelectTarget>::Marker, Cons<T, Nil>>, <<Columns as IntoSelectTarget>::Marker as ResolveRow<T>>::Row>
where Columns: ExprSources + ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget, Columns::Sources: SourcesIn<Cons<T, M>, ScopeProof>, Columns::Marker: ResolveRow<T>,

Adds RETURNING columns after FROM.

Source§

impl<'a, S, T, M> QueryBuilder<'a, S, UpdateWhereSet, T, M>

Source

pub fn returning<Columns, ScopeProof>( self, columns: Columns, ) -> UpdateBuilder<'a, S, UpdateReturningSet, T, Scoped<<Columns as IntoSelectTarget>::Marker, Cons<T, Nil>>, <<Columns as IntoSelectTarget>::Marker as ResolveRow<T>>::Row>
where Columns: ExprSources + ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget, Columns::Sources: SourcesIn<Cons<T, M>, ScopeProof>, Columns::Marker: ResolveRow<T>,

Adds RETURNING columns after WHERE.

Source§

impl<'a, Schema, State, Table, Marker, Row, Grouped> QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>
where State: ExecutableState,

Source

pub fn comment(self, text: impl AsRef<str>) -> Self

Prepends a sqlcommenter comment to the statement.

The text is wrapped in /* ... */. Any /* or */ in the input is neutralised so it cannot end the comment early. Empty text adds nothing.

§Examples
let query = db.select(user.id).from(user).comment("list-users");
assert_eq!(query.to_sql().sql(), r#"/*list-users*/ SELECT "users"."id" FROM "users""#);
Source

pub fn comment_tags<I, K, V>(self, pairs: I) -> Self
where I: IntoIterator<Item = (K, V)>, K: AsRef<str>, V: AsRef<str>,

Prepends a key-value sqlcommenter comment to the statement.

Each pair renders as key='value', URL-encoded. Pairs are sorted by key, joined with , and wrapped in /* ... */. Pairs with an empty value are skipped; if none remain, nothing is added.

§Examples
let query = db
    .select(user.id)
    .from(user)
    .comment_tags([("route", "/users"), ("action", "list")]);
let sql = query.to_sql().sql();
assert!(sql.starts_with("/*action='list',route='%2Fusers'*/"));
Source§

impl<'a> QueryBuilder<'a>

Source

pub const fn new<S>() -> QueryBuilder<'a, S, BuilderInit>

Creates a query builder for schema S.

§Examples
let db = QueryBuilder::new::<Schema>();
let query = db.select(()).from(user);
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."id", "users"."name", "users"."email" FROM "users""#
);
Source§

impl<'a, Schema> QueryBuilder<'a, Schema, BuilderInit>

Source

pub fn select<T>( &self, columns: T, ) -> SelectBuilder<'a, Schema, SelectInitial, (), T::Marker>
where T: ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget,

Starts a SELECT of the given columns.

Pass one column or expression, a tuple of them, or () for every column of the FROM table. Continue with .from(table).

§Examples
use drizzle::core::expr::eq;

let query = db
    .select((user.name, post.title))
    .from(user)
    .join((post, eq(post.author_id, user.id)));
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."name", "posts"."title" FROM "users" JOIN "posts" ON "posts"."author_id" = "users"."id""#
);
Source

pub fn select_distinct<T>( &self, columns: T, ) -> SelectBuilder<'a, Schema, SelectInitial, (), T::Marker>
where T: ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget,

Starts a SELECT DISTINCT, which drops duplicate rows.

§Examples
let query = db.select_distinct(user.name).from(user);
assert_eq!(query.to_sql().sql(), r#"SELECT DISTINCT "users"."name" FROM "users""#);
Source

pub fn select_distinct_on<On, Columns>( &self, on: On, columns: Columns, ) -> SelectBuilder<'a, Schema, SelectInitial, (), Columns::Marker>
where On: ToSQL<'a, PostgresValue<'a>>, Columns: ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget,

Starts a SELECT DISTINCT ON (...), which keeps one row per distinct value of on.

The first row of each group wins, so add an order_by that starts with the on columns to choose which row is kept.

§Examples
let query = db
    .select_distinct_on(user.email, (user.id, user.email))
    .from(user)
    .order_by(user.email);
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT DISTINCT ON ("users"."email") "users"."id", "users"."email" FROM "users" ORDER BY "users"."email""#
);
Source§

impl<'a, Schema> QueryBuilder<'a, Schema, CTEInit>

Source

pub fn select<T>( &self, columns: T, ) -> SelectBuilder<'a, Schema, SelectInitial, (), T::Marker>
where T: ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget,

Starts the main SELECT after WITH .... See QueryBuilder::with.

Source

pub fn select_distinct<T>( &self, columns: T, ) -> SelectBuilder<'a, Schema, SelectInitial, (), T::Marker>
where T: ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget,

Starts the main SELECT DISTINCT after WITH ....

Source

pub fn select_distinct_on<On, Columns>( &self, on: On, columns: Columns, ) -> SelectBuilder<'a, Schema, SelectInitial, (), Columns::Marker>
where On: ToSQL<'a, PostgresValue<'a>>, Columns: ToSQL<'a, PostgresValue<'a>> + IntoSelectTarget,

Starts the main SELECT DISTINCT ON (...) after WITH ....

Source

pub fn insert<Table>( &self, table: Table, ) -> InsertBuilder<'a, Schema, InsertInitial, Table>
where Table: PostgresTable<'a>,

Starts the main INSERT after WITH ....

Source

pub fn update<Table>( &self, table: Table, ) -> UpdateBuilder<'a, Schema, UpdateInitial, Table>
where Table: PostgresTable<'a>,

Starts the main UPDATE after WITH ....

Source

pub fn delete<Table>( &self, table: Table, ) -> DeleteBuilder<'a, Schema, DeleteInitial, Table>
where Table: PostgresTable<'a>,

Starts the main DELETE after WITH ....

Source

pub fn with<C>(&self, cte: &C) -> Self
where C: CTEDefinition<'a>,

Adds another common table expression to the WITH list.

Source§

impl<'a, Schema> QueryBuilder<'a, Schema, BuilderInit>

Source

pub fn insert<Table>( &self, table: Table, ) -> InsertBuilder<'a, Schema, InsertInitial, Table>
where Table: PostgresTable<'a>,

Starts an INSERT INTO table. Continue with .values(...) or .select(...).

§Examples
let query = db.insert(user).values([InsertUser::new("Alice")]);
assert_eq!(query.to_sql().sql(), r#"INSERT INTO "users" ("name") VALUES ($1)"#);
Source

pub fn update<Table>( &self, table: Table, ) -> UpdateBuilder<'a, Schema, UpdateInitial, Table>
where Table: PostgresTable<'a>,

Starts an UPDATE table. Continue with .set(...).

§Examples
use drizzle::core::expr::eq;

let query = db
    .update(user)
    .set(UpdateUser::default().with_name("Bob"))
    .r#where(eq(user.id, 1));
assert_eq!(
    query.to_sql().sql(),
    r#"UPDATE "users" SET "name" = $1 WHERE "users"."id" = $2"#
);
Source

pub fn delete<Table>( &self, table: Table, ) -> DeleteBuilder<'a, Schema, DeleteInitial, Table>
where Table: PostgresTable<'a>,

Starts a DELETE FROM table.

Without .where(...) the statement deletes every row.

§Examples
use drizzle::core::expr::gt;

let query = db.delete(user).r#where(gt(user.id, 10));
assert_eq!(query.to_sql().sql(), r#"DELETE FROM "users" WHERE "users"."id" > $1"#);
Source

pub fn with<C>(&self, cte: &C) -> QueryBuilder<'a, Schema, CTEInit>
where C: CTEDefinition<'a>,

Starts a WITH clause from a common table expression (CTE).

Build the CTE with SelectBuilder::into_cte::<Tag>(), then reference it in the main statement through its .table field. Chain more .with(...) calls to add more CTEs.

§Examples
use drizzle::core::expr::gt;

struct Recent;
impl drizzle::core::Tag for Recent {
    const NAME: &'static str = "recent";
}

let recent = db
    .select((user.id, user.name))
    .from(user)
    .r#where(gt(user.id, 100))
    .into_cte::<Recent>();
let r = recent.table;

let query = db.with(&recent).select(r.name).from(&recent);
assert_eq!(
    query.to_sql().sql(),
    r#"WITH "recent" AS (SELECT "users"."id", "users"."name" FROM "users" WHERE "users"."id" > $1) SELECT "recent"."name" FROM "recent""#
);

Trait Implementations§

Source§

impl<'a, Schema: Clone, State: Clone, Table: Clone, Marker: Clone, Row: Clone, Grouped: Clone> Clone for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, Schema: Debug, State: Debug, Table: Debug, Marker: Debug, Row: Debug, Grouped: Debug> Debug for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, Schema: Default, State: Default, Table: Default, Marker: Default, Row: Default, Grouped: Default> Default for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>

Source§

fn default() -> Self

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

impl<'a, Schema, State, Table, Marker, Row, Grouped> ToSQL<'a, PostgresValue<'a>> for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>

Source§

fn to_sql(&self) -> SQL<'a, PostgresValue<'a>>

Renders self as a SQL fragment.
Source§

fn into_sql(self) -> SQL<'a, V>
where Self: Sized,

Renders self as a SQL fragment, consuming it. Read more

Auto Trait Implementations§

§

impl<'a, Schema = (), State = (), Table = (), Marker = (), Row = (), Grouped = ()> !RefUnwindSafe for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>

§

impl<'a, Schema = (), State = (), Table = (), Marker = (), Row = (), Grouped = ()> !UnwindSafe for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>

§

impl<'a, Schema, State, Table, Marker, Row, Grouped> Freeze for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>
where PhantomData<Schema>: Freeze, PhantomData<State>: Freeze, PhantomData<Table>: Freeze, PhantomData<Marker>: Freeze, PhantomData<Row>: Freeze, PhantomData<Grouped>: Freeze,

§

impl<'a, Schema, State, Table, Marker, Row, Grouped> Send for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>
where PhantomData<Schema>: Send, PhantomData<State>: Send, PhantomData<Table>: Send, PhantomData<Marker>: Send, PhantomData<Row>: Send, PhantomData<Grouped>: Send,

§

impl<'a, Schema, State, Table, Marker, Row, Grouped> Sync for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>
where PhantomData<Schema>: Sync, PhantomData<State>: Sync, PhantomData<Table>: Sync, PhantomData<Marker>: Sync, PhantomData<Row>: Sync, PhantomData<Grouped>: Sync,

§

impl<'a, Schema, State, Table, Marker, Row, Grouped> Unpin for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>
where PhantomData<Schema>: Unpin, PhantomData<State>: Unpin, PhantomData<Table>: Unpin, PhantomData<Marker>: Unpin, PhantomData<Row>: Unpin, PhantomData<Grouped>: Unpin,

§

impl<'a, Schema, State, Table, Marker, Row, Grouped> UnsafeUnpin for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>

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<'a, E> ArrayExprExt<'a> for E
where E: Expr<'a, PostgresValue<'a>>,

Source§

fn array_contains<R>( self, other: R, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <Self::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<Self::Nullable, Self::Sources>, Arg<R::Nullable, R::Sources>)>
where R: Expr<'a, PostgresValue<'a>>, Self::SQLType: ArrayOperand<R::SQLType>,

Tests whether self contains every element of other (@>). Read more
Source§

fn array_contained<R>( self, other: R, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <Self::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<Self::Nullable, Self::Sources>, Arg<R::Nullable, R::Sources>)>
where R: Expr<'a, PostgresValue<'a>>, Self::SQLType: ArrayOperand<R::SQLType>,

Tests whether every element of self is in other (<@). Read more
Source§

fn array_overlaps<R>( self, other: R, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <Self::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<Self::Nullable, Self::Sources>, Arg<R::Nullable, R::Sources>)>
where R: Expr<'a, PostgresValue<'a>>, Self::SQLType: ArrayOperand<R::SQLType>,

Tests whether self and other share at least one element (&&). 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<'a, V, L, R> ComparisonOperand<'a, V, L> for R
where V: SQLParam + 'a, L: Expr<'a, V>, R: Expr<'a, V>, <L as Expr<'a, V>>::SQLType: Compatible<<R as Expr<'a, V>>::SQLType>,

Source§

type SQLType = <R as Expr<'a, V>>::SQLType

SQL type of the operand.
Source§

type Nullable = <R as Expr<'a, V>>::Nullable

Whether the operand can be NULL.
Source§

type Aggregate = <R as Expr<'a, V>>::Aggregate

Whether the operand is an aggregate.
Source§

type Sources = <R as ExprSources>::Sources

Tables the operand reads; see ExprSources::Sources.
Source§

fn into_comparison_sql(self) -> SQL<'a, V>

Renders the operand.
Source§

impl<'a, V, E> ExprExt<'a, V> for E
where V: SQLParam, E: Expr<'a, V>,

Source§

fn eq<R>( self, other: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggregateKind>::Or<<R as ComparisonOperand<'a, V, Self>>::Aggregate>, ((Self::Nullable, Self::Sources), (<R as ComparisonOperand<'a, V, Self>>::Nullable, <R as ComparisonOperand<'a, V, Self>>::Sources))>
where R: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<R as ComparisonOperand<'a, V, Self>>::SQLType>,

Equality comparison (=); see eq.
Source§

fn ne<R>( self, other: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggregateKind>::Or<<R as ComparisonOperand<'a, V, Self>>::Aggregate>, ((Self::Nullable, Self::Sources), (<R as ComparisonOperand<'a, V, Self>>::Nullable, <R as ComparisonOperand<'a, V, Self>>::Sources))>
where R: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<R as ComparisonOperand<'a, V, Self>>::SQLType>,

Inequality comparison (<>); see ne.
Source§

fn gt<R>( self, other: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggregateKind>::Or<<R as ComparisonOperand<'a, V, Self>>::Aggregate>, ((Self::Nullable, Self::Sources), (<R as ComparisonOperand<'a, V, Self>>::Nullable, <R as ComparisonOperand<'a, V, Self>>::Sources))>
where R: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<R as ComparisonOperand<'a, V, Self>>::SQLType>,

Greater-than comparison (>); see gt.
Source§

fn ge<R>( self, other: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggregateKind>::Or<<R as ComparisonOperand<'a, V, Self>>::Aggregate>, ((Self::Nullable, Self::Sources), (<R as ComparisonOperand<'a, V, Self>>::Nullable, <R as ComparisonOperand<'a, V, Self>>::Sources))>
where R: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<R as ComparisonOperand<'a, V, Self>>::SQLType>,

Greater-than-or-equal comparison (>=); see gte.
Source§

fn lt<R>( self, other: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggregateKind>::Or<<R as ComparisonOperand<'a, V, Self>>::Aggregate>, ((Self::Nullable, Self::Sources), (<R as ComparisonOperand<'a, V, Self>>::Nullable, <R as ComparisonOperand<'a, V, Self>>::Sources))>
where R: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<R as ComparisonOperand<'a, V, Self>>::SQLType>,

Less-than comparison (<); see lt.
Source§

fn le<R>( self, other: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggregateKind>::Or<<R as ComparisonOperand<'a, V, Self>>::Aggregate>, ((Self::Nullable, Self::Sources), (<R as ComparisonOperand<'a, V, Self>>::Nullable, <R as ComparisonOperand<'a, V, Self>>::Sources))>
where R: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<R as ComparisonOperand<'a, V, Self>>::SQLType>,

Less-than-or-equal comparison (<=); see lte.
Source§

fn like<R>( self, pattern: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggregateKind>::Or<<R as ComparisonOperand<'a, V, Self>>::Aggregate>, ((Self::Nullable, Self::Sources), (<R as ComparisonOperand<'a, V, Self>>::Nullable, <R as ComparisonOperand<'a, V, Self>>::Sources))>
where R: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<R as ComparisonOperand<'a, V, Self>>::SQLType> + Textual, <R as ComparisonOperand<'a, V, Self>>::SQLType: Textual,

Pattern match (LIKE); see like.
Source§

fn not_like<R>( self, pattern: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggregateKind>::Or<<R as ComparisonOperand<'a, V, Self>>::Aggregate>, ((Self::Nullable, Self::Sources), (<R as ComparisonOperand<'a, V, Self>>::Nullable, <R as ComparisonOperand<'a, V, Self>>::Sources))>
where R: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<R as ComparisonOperand<'a, V, Self>>::SQLType> + Textual, <R as ComparisonOperand<'a, V, Self>>::SQLType: Textual,

Negated pattern match (NOT LIKE); see not_like.
Source§

fn is_null( self, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, Self::Aggregate, Coalesce<Self::Sources, NonNull>>

NULL check (IS NULL); see is_null.
Source§

fn is_not_null( self, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, Self::Aggregate, Coalesce<Self::Sources, NonNull>>

Non-NULL check (IS NOT NULL); see is_not_null.
Source§

fn between<L, H>( self, low: L, high: H, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <<Self::Aggregate as AggregateKind>::Or<<L as ComparisonOperand<'a, V, Self>>::Aggregate> as AggregateKind>::Or<<H as ComparisonOperand<'a, V, Self>>::Aggregate>, ((Self::Nullable, Self::Sources), ((<L as ComparisonOperand<'a, V, Self>>::Nullable, <L as ComparisonOperand<'a, V, Self>>::Sources), (<H as ComparisonOperand<'a, V, Self>>::Nullable, <H as ComparisonOperand<'a, V, Self>>::Sources)))>
where L: ComparisonOperand<'a, V, Self>, H: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<L as ComparisonOperand<'a, V, Self>>::SQLType> + Compatible<<H as ComparisonOperand<'a, V, Self>>::SQLType>,

Inclusive range check (BETWEEN); see between.
Source§

fn not_between<L, H>( self, low: L, high: H, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <<Self::Aggregate as AggregateKind>::Or<<L as ComparisonOperand<'a, V, Self>>::Aggregate> as AggregateKind>::Or<<H as ComparisonOperand<'a, V, Self>>::Aggregate>, ((Self::Nullable, Self::Sources), ((<L as ComparisonOperand<'a, V, Self>>::Nullable, <L as ComparisonOperand<'a, V, Self>>::Sources), (<H as ComparisonOperand<'a, V, Self>>::Nullable, <H as ComparisonOperand<'a, V, Self>>::Sources)))>
where L: ComparisonOperand<'a, V, Self>, H: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<L as ComparisonOperand<'a, V, Self>>::SQLType> + Compatible<<H as ComparisonOperand<'a, V, Self>>::SQLType>,

Negated range check (NOT BETWEEN); see not_between.
Source§

fn in_array<I, R>( self, values: I, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, Self::Aggregate, ((Self::Nullable, Self::Sources), (<R as Expr<'a, V>>::Nullable, <R as ExprSources>::Sources))>
where I: IntoIterator<Item = R>, R: Expr<'a, V>, Self::SQLType: Compatible<<R as Expr<'a, V>>::SQLType>,

Membership in a list of values (IN (...)); see in_array.
Source§

fn not_in_array<I, R>( self, values: I, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, Self::Aggregate, ((Self::Nullable, Self::Sources), (<R as Expr<'a, V>>::Nullable, <R as ExprSources>::Sources))>
where I: IntoIterator<Item = R>, R: Expr<'a, V>, Self::SQLType: Compatible<<R as Expr<'a, V>>::SQLType>,

Non-membership in a list of values (NOT IN (...)); see not_in_array.
Source§

fn in_subquery<S>( self, subquery: S, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, Self::Aggregate, ((Self::Nullable, Self::Sources), (<S as Expr<'a, V>>::Nullable, <S as ExprSources>::Sources))>
where S: Expr<'a, V>, Self::SQLType: Compatible<<S as Expr<'a, V>>::SQLType> + Compatible,

Membership in a subquery’s rows (IN (SELECT ...)); see in_subquery.
Source§

fn not_in_subquery<S>( self, subquery: S, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, Self::Aggregate, ((Self::Nullable, Self::Sources), (<S as Expr<'a, V>>::Nullable, <S as ExprSources>::Sources))>
where S: Expr<'a, V>, Self::SQLType: Compatible<<S as Expr<'a, V>>::SQLType> + Compatible,

Non-membership in a subquery’s rows (NOT IN (SELECT ...)); see not_in_subquery.
Source§

fn is_distinct_from<R>( self, other: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggregateKind>::Or<<R as ComparisonOperand<'a, V, Self>>::Aggregate>, Coalesce<(Self::Sources, <R as ComparisonOperand<'a, V, Self>>::Sources), NonNull>>
where R: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<R as ComparisonOperand<'a, V, Self>>::SQLType>,

NULL-safe inequality (IS DISTINCT FROM); see is_distinct_from.
Source§

fn is_not_distinct_from<R>( self, other: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggregateKind>::Or<<R as ComparisonOperand<'a, V, Self>>::Aggregate>, Coalesce<(Self::Sources, <R as ComparisonOperand<'a, V, Self>>::Sources), NonNull>>
where R: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<R as ComparisonOperand<'a, V, Self>>::SQLType>,

NULL-safe equality (IS NOT DISTINCT FROM); see is_not_distinct_from.
Source§

fn is_true( self, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, Self::Aggregate, Coalesce<Self::Sources, NonNull>>

Truth test (IS TRUE); see is_true.
Source§

fn is_false( self, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, Self::Aggregate, Coalesce<Self::Sources, NonNull>>

Falsity test (IS FALSE); see is_false.
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<'a, E> JsonExprExt<'a> for E
where E: Expr<'a, PostgresValue<'a>>,

Source§

fn json_get( self, key: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType,

Gets an object field by key (->), keeping the JSON type. See json_get.
Source§

fn json_get_idx( self, index: i32, ) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType,

Gets an array element by index (->), keeping the JSON type. See json_get_idx.
Source§

fn json_get_text( self, key: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType,

Gets an object field by key as text (->>). See json_get_text.
Source§

fn json_get_text_idx( self, index: i32, ) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType,

Gets an array element by index as text (->>). See json_get_text_idx.
Source§

fn json_get_path( self, path: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, <Self::SQLType as JsonType>::Field, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType,

Gets the value at a path (#>), keeping the JSON type. See json_get_path.
Source§

fn json_get_path_text( self, path: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Text, Null, Self::Aggregate, Self::Sources>
where Self::SQLType: JsonType,

Gets the value at a path as text (#>>). See json_get_path_text.
Source§

fn jsonb_contains<R>( self, other: R, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <Self::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<Self::Nullable, Self::Sources>, Arg<R::Nullable, R::Sources>)>
where Self::SQLType: JsonbType, R: Expr<'a, PostgresValue<'a>>, R::SQLType: JsonbOperand,

Tests whether self contains other (@>, jsonb only). See jsonb_contains.
Source§

fn jsonb_contained<R>( self, other: R, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, <Self::Aggregate as AggregateKind>::Or<R::Aggregate>, (Arg<Self::Nullable, Self::Sources>, Arg<R::Nullable, R::Sources>)>
where Self::SQLType: JsonbType, R: Expr<'a, PostgresValue<'a>>, R::SQLType: JsonbOperand,

Tests whether self is contained in other (<@, jsonb only). See jsonb_contained.
Source§

fn jsonb_exists_key( self, key: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, Self::Aggregate, Arg<Self::Nullable, Self::Sources>>
where Self::SQLType: JsonbType,

Tests whether a top-level key exists (?, jsonb only). See jsonb_exists_key.
Source§

impl<List> ListIncludes<Nil, ()> for List

Source§

impl<Mk> MarkerAggValidFor<()> for Mk

Source§

impl<'a, E> RegexExprExt<'a> for E
where E: Expr<'a, PostgresValue<'a>>,

Source§

fn regex_match( self, pattern: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, Self::Aggregate, Arg<Self::Nullable, Self::Sources>>
where Self::SQLType: Textual,

Tests whether self matches pattern, case-sensitively (~). See regex_match.
Source§

fn regex_match_ci( self, pattern: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, Self::Aggregate, Arg<Self::Nullable, Self::Sources>>
where Self::SQLType: Textual,

Tests whether self matches pattern, ignoring case (~*). See regex_match_ci.
Source§

fn regex_not_match( self, pattern: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, Self::Aggregate, Arg<Self::Nullable, Self::Sources>>
where Self::SQLType: Textual,

Tests whether self does not match pattern, case-sensitively (!~). See regex_not_match.
Source§

fn regex_not_match_ci( self, pattern: &'a str, ) -> SQLExpr<'a, PostgresValue<'a>, Boolean, NonNull, Self::Aggregate, Arg<Self::Nullable, Self::Sources>>
where Self::SQLType: Textual,

Tests whether self does not match pattern, ignoring case (!~*). See regex_not_match_ci.
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.
Source§

impl<T> TypeEq<T> for T