Skip to main content

QueryBuilder

Struct QueryBuilder 

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

Main query builder for PostgreSQL

The S type parameter represents the schema type, which is used to ensure type safety when building queries.

Fields§

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

Implementations§

Source§

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

Source

pub fn where( self, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> DeleteBuilder<'a, S, DeleteWhereSet, T>

Adds a WHERE condition to the query

Source

pub fn returning( self, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> DeleteBuilder<'a, S, DeleteReturningSet, T>

Adds a RETURNING clause to the query

Source§

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

Source

pub fn returning( self, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> DeleteBuilder<'a, S, DeleteReturningSet, T>

Adds a RETURNING clause after WHERE

Source§

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

Source

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

Sets values to insert and transitions to ValuesSet state

Source§

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

Source

pub fn on_conflict( self, conflict: Conflict<'a>, ) -> InsertBuilder<'a, S, InsertOnConflictSet, T>

Adds conflict resolution clause following PostgreSQL ON CONFLICT syntax

Source

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

Shorthand for ON CONFLICT DO NOTHING (matches any conflict)

Source

pub fn on_conflict_do_nothing_on<C>( self, columns: C, ) -> InsertBuilder<'a, S, InsertOnConflictSet, T>
where C: ToSQL<'a, PostgresValue<'a>>,

Shorthand for ON CONFLICT (columns…) DO NOTHING

Source

pub fn returning( self, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> InsertBuilder<'a, S, InsertReturningSet, T>

Adds a RETURNING clause and transitions to ReturningSet state

Source§

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

Source

pub fn returning( self, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> InsertBuilder<'a, S, InsertReturningSet, T>

Adds a RETURNING clause after ON CONFLICT

Source§

impl<'a, S> QueryBuilder<'a, S, SelectInitial>

Source

pub fn from<T>(self, query: T) -> SelectBuilder<'a, S, SelectFromSet, T>
where T: ToSQL<'a, PostgresValue<'a>>,

Specifies the table to select FROM and transitions state

Source§

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

Source

pub fn join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

Adds a JOIN clause to the query

Source

pub fn natural_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_left_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn left_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn left_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_left_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_right_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn right_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn right_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_right_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_full_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn full_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn full_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_full_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn inner_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn cross_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn left_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn left_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn right_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn right_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn full_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn full_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn inner_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn where( self, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectWhereSet, T>

Source

pub fn group_by( self, expressions: impl IntoIterator<Item = impl ToSQL<'a, PostgresValue<'a>>>, ) -> SelectBuilder<'a, S, SelectGroupSet, T>

Adds a GROUP BY clause to the query

Source

pub fn limit(self, limit: usize) -> SelectBuilder<'a, S, SelectLimitSet, T>

Limits the number of rows returned

Source

pub fn offset(self, offset: usize) -> SelectBuilder<'a, S, SelectOffsetSet, T>

Sets the offset for the query results

Source

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

Sorts the query results

Source§

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

Source

pub fn where( self, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectWhereSet, T>

Adds a WHERE condition after a JOIN

Source

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

Sorts the query results

Source

pub fn join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

Adds a JOIN clause to the query

Source

pub fn natural_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_left_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn left_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn left_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_left_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_right_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn right_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn right_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_right_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_full_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn full_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn full_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn natural_full_outer_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn inner_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn cross_join<U: PostgresTable<'a>>( self, table: U, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with ON clause

Source

pub fn left_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn left_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn right_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn right_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn full_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn full_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn inner_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, T>

JOIN with USING clause (PostgreSQL-specific)

Source§

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

Source

pub fn group_by( self, expressions: impl IntoIterator<Item = impl ToSQL<'a, PostgresValue<'a>>>, ) -> SelectBuilder<'a, S, SelectGroupSet, T>

Adds a GROUP BY clause after a WHERE

Source

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

Adds an ORDER BY clause after a WHERE

Source

pub fn limit(self, limit: usize) -> SelectBuilder<'a, S, SelectLimitSet, T>

Adds a LIMIT clause after a WHERE

Source§

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

Source

pub fn having( self, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectGroupSet, T>

Adds a HAVING clause after GROUP BY

Source

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

Adds an ORDER BY clause after GROUP BY

Source§

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

Source

pub fn limit(self, limit: usize) -> SelectBuilder<'a, S, SelectLimitSet, T>

Adds a LIMIT clause after ORDER BY

Source§

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

Source

pub fn offset(self, offset: usize) -> SelectBuilder<'a, S, SelectOffsetSet, T>

Adds an OFFSET clause after LIMIT

Source§

impl<'a, S, State, T> QueryBuilder<'a, S, State, T>
where State: AsCteState, T: SQLTable<'a, PostgresSchemaType, PostgresValue<'a>>,

Source

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

Converts this SELECT query into a CTE (Common Table Expression) with the given name.

Source§

impl<'a, S, State, T> QueryBuilder<'a, S, State, T>
where State: ExecutableState,

Source

pub fn union( self, other: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T>

Combines this query with another using UNION.

Source

pub fn union_all( self, other: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T>

Combines this query with another using UNION ALL.

Source

pub fn intersect( self, other: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T>

Combines this query with another using INTERSECT.

Source

pub fn intersect_all( self, other: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T>

Combines this query with another using INTERSECT ALL.

Source

pub fn except( self, other: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T>

Combines this query with another using EXCEPT.

Source

pub fn except_all( self, other: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T>

Combines this query with another using EXCEPT ALL.

Source§

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

Source

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

Sorts the results of a set operation.

Source

pub fn limit(self, limit: usize) -> SelectBuilder<'a, S, SelectLimitSet, T>

Limits the results of a set operation.

Source

pub fn offset(self, offset: usize) -> SelectBuilder<'a, S, SelectOffsetSet, T>

Offsets the results of a set operation.

Source§

impl<'a, S, State, T> QueryBuilder<'a, S, State, T>
where State: ForLockableState,

Source

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

Adds FOR UPDATE clause to lock selected rows for update.

This prevents other transactions from modifying or locking the selected rows until the current transaction ends.

§Example
db.select(()).from(users).where(eq(users.id, 1)).for_update()
// SELECT ... FROM "users" WHERE "id" = $1 FOR UPDATE
Source

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

Adds FOR SHARE clause to lock selected rows for shared access.

This allows other transactions to read the rows but prevents them from modifying or exclusively locking them.

§Example
db.select(()).from(users).where(eq(users.id, 1)).for_share()
// SELECT ... FROM "users" WHERE "id" = $1 FOR SHARE
Source

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

Adds FOR NO KEY UPDATE clause.

Similar to FOR UPDATE but weaker - allows SELECT FOR KEY SHARE on the same rows.

§Example
db.select(()).from(users).where(eq(users.id, 1)).for_no_key_update()
// SELECT ... FROM "users" WHERE "id" = $1 FOR NO KEY UPDATE
Source

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

Adds FOR KEY SHARE clause.

The weakest lock - only blocks SELECT FOR UPDATE.

§Example
db.select(()).from(users).where(eq(users.id, 1)).for_key_share()
// SELECT ... FROM "users" WHERE "id" = $1 FOR KEY SHARE
Source

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

Adds FOR UPDATE OF table clause to lock only rows from a specific table.

Useful in joins to specify which table’s rows should be locked. Note: Uses unqualified table name per PostgreSQL requirements.

§Example
db.select(())
    .from(users)
    .join(orders, eq(users.id, orders.user_id))
    .for_update_of(users)
// SELECT ... FOR UPDATE OF "users"
Source

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

Adds FOR SHARE OF table clause to lock only rows from a specific table.

Useful in joins to specify which table’s rows should be locked. Note: Uses unqualified table name per PostgreSQL requirements.

§Example
db.select(())
    .from(users)
    .join(orders, eq(users.id, orders.user_id))
    .for_share_of(users)
// SELECT ... FOR SHARE OF "users"
Source§

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

Source

pub fn nowait(self) -> SelectBuilder<'a, S, SelectForSet, T>

Adds NOWAIT option to fail immediately if rows are locked.

Instead of waiting for locked rows to become available, the query will fail with an error if any selected rows are currently locked.

§Example
db.select(()).from(users).for_update().nowait()
// SELECT ... FOR UPDATE NOWAIT
Source

pub fn skip_locked(self) -> SelectBuilder<'a, S, SelectForSet, T>

Adds SKIP LOCKED option to skip over locked rows.

Instead of waiting for locked rows, the query will skip them and only return/lock rows that are currently available.

§Example
db.select(()).from(jobs).where(eq(jobs.status, "pending")).for_update().skip_locked()
// SELECT ... FOR UPDATE SKIP LOCKED
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 values to update and transitions to the SetClauseSet state

Source§

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

Source

pub fn from( self, source: impl ToSQL<'a, PostgresValue<'a>>, ) -> UpdateBuilder<'a, S, UpdateFromSet, T>

Adds a FROM clause and transitions to the FromSet state

Source

pub fn where( self, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> UpdateBuilder<'a, S, UpdateWhereSet, T>

Adds a WHERE condition and transitions to the WhereSet state

Source

pub fn returning( self, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> UpdateBuilder<'a, S, UpdateReturningSet, T>

Adds a RETURNING clause and transitions to the ReturningSet state

Source§

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

Source

pub fn where( self, condition: impl ToSQL<'a, PostgresValue<'a>>, ) -> UpdateBuilder<'a, S, UpdateWhereSet, T>

Adds a WHERE condition after FROM

Source

pub fn returning( self, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> UpdateBuilder<'a, S, UpdateReturningSet, T>

Adds a RETURNING clause after FROM

Source§

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

Source

pub fn returning( self, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> UpdateBuilder<'a, S, UpdateReturningSet, T>

Adds a RETURNING clause after WHERE

Source§

impl<'a> QueryBuilder<'a>

Source

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

Creates a new query builder for the given schema

Source§

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

Source

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

Source

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

Begins a SELECT DISTINCT query with the specified columns.

SELECT DISTINCT removes duplicate rows from the result set.

Source

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

Begins a SELECT DISTINCT ON query with the specified columns.

Source§

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

Source

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

Source

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

Begins a SELECT DISTINCT query with the specified columns after a CTE.

Source

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

Begins a SELECT DISTINCT ON query with the specified columns after a CTE.

Source

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

Begins an INSERT query after a CTE.

Source

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

Begins an UPDATE query after a CTE.

Source

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

Begins a DELETE query after a CTE.

Source

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

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>,

Source

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

Source

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

Source

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

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> QueryBuilder<'a, Schema, State, Table>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

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

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> Default for QueryBuilder<'a, Schema, State, Table>

Source§

fn default() -> QueryBuilder<'a, Schema, State, Table>

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

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

Source§

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

Source§

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

Consume self and return SQL without cloning. Default delegates to to_sql() (which clones). Types that own their SQL (like SQL and SQLExpr) override this to avoid the clone.
Source§

fn alias(&self, alias: &'static str) -> SQL<'a, V>

Auto Trait Implementations§

§

impl<'a, Schema, State, Table> Freeze for QueryBuilder<'a, Schema, State, Table>

§

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

§

impl<'a, Schema, State, Table> Send for QueryBuilder<'a, Schema, State, Table>
where Schema: Send, State: Send, Table: Send,

§

impl<'a, Schema, State, Table> Sync for QueryBuilder<'a, Schema, State, Table>
where Schema: Sync, State: Sync, Table: Sync,

§

impl<'a, Schema, State, Table> Unpin for QueryBuilder<'a, Schema, State, Table>
where Schema: Unpin, State: Unpin, Table: Unpin,

§

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

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.