Skip to main content

QueryBuilder

Struct QueryBuilder 

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

Main query builder for SQLite operations.

QueryBuilder provides a type-safe, fluent API for building SQL queries. It uses compile-time type checking to ensure queries are valid and properly structured.

§Type Parameters

  • Schema: The database schema type, ensuring queries only reference valid tables
  • State: The current builder state, enforcing proper query construction order
  • Table: The table type being operated on (for single-table operations)

§Basic Usage

use drizzle::sqlite::prelude::*;
use drizzle::sqlite::builder::QueryBuilder;

#[SQLiteTable(name = "users")]
struct User {
    #[column(primary)]
    id: i32,
    name: String,
}

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

// Create a query builder for your schema
let builder = QueryBuilder::new::<Schema>();
let Schema { user } = Schema::new();

// Build queries using the fluent API
let query = builder
    .select(user.name)
    .from(user);
assert_eq!(query.to_sql().sql(), r#"SELECT "users"."name" FROM "users""#);

§Query Types

The builder supports all major SQL operations:

§SELECT Queries

let query = builder.select(user.name).from(user);
let query = builder.select((user.id, user.name)).from(user).r#where(gt(user.id, 10));

§INSERT Queries

let query = builder
    .insert(user)
    .values([InsertUser::new("Alice")]);

§UPDATE Queries

let query = builder
    .update(user)
    .set(UpdateUser::default().with_name("Bob"))
    .r#where(eq(user.id, 1));

§DELETE Queries

let query = builder
    .delete(user)
    .r#where(lt(user.id, 10));

§Common Table Expressions (CTEs)

The builder supports WITH clauses for complex queries with typed field access:

// Create a CTE with typed field access using .into_cte::<Tag>()
let active_users = builder
    .select((user.id, user.name))
    .from(user)
    .into_cte::<ActiveUsersTag>();

// Use the CTE with typed column access via Deref
let query = builder
    .with(&active_users)
    .select(active_users.name)  // Typed field access!
    .from(&active_users);
assert_eq!(
    query.to_sql().sql(),
    r#"WITH active_users AS (SELECT "users"."id", "users"."name" FROM "users") SELECT "active_users"."name" FROM "active_users""#
);

Fields§

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

Implementations§

Source§

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

Source

pub fn where<E>(self, condition: E) -> DeleteBuilder<'a, S, DeleteWhereSet, T>
where E: Expr<'a, SQLiteValue<'a>>, E::SQLType: BooleanLike,

Adds a WHERE clause to specify which rows to delete.

Warning: Without a WHERE clause, ALL rows in the table will be deleted! Always use this method unless you specifically intend to truncate the entire table.

§Examples
// Delete specific row by ID
let query = builder
    .delete(user)
    .r#where(eq(user.id, 1));
assert_eq!(query.to_sql().sql(), r#"DELETE FROM "users" WHERE "users"."id" = ?"#);

// Delete with complex conditions
let query = builder
    .delete(user)
    .r#where(and(
        gt(user.id, 100),
        or(eq(user.name, "test"), eq(user.age, 0))
    ));
Source

pub fn returning<Columns>( 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: ToSQL<'a, SQLiteValue<'a>> + IntoSelectTarget, Columns::Marker: ResolveRow<T>,

Adds a RETURNING clause to the query

Source§

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

Source

pub fn returning<Columns>( 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: ToSQL<'a, SQLiteValue<'a>> + IntoSelectTarget, Columns::Marker: ResolveRow<T>,

Adds a RETURNING clause after WHERE

Source§

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

Source

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

Specifies a single row to insert into the table.

Accepts an insert value object generated by the SQLiteTable macro (e.g., InsertUser).

Source

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

Specifies the values to insert into the table.

Accepts an iterable of insert value objects generated by the SQLiteTable macro (e.g., InsertUser).

Source

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

Inserts rows produced by a SELECT query without an explicit column list.

The SELECT output must provide every table column in declaration order.

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>

Begins a typed ON CONFLICT clause targeting a specific constraint.

The target must implement ConflictTarget<T>, which is auto-generated for primary key columns, unique columns, and unique indexes.

Returns an OnConflictBuilder to specify do_nothing() or do_update().

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

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

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

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

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

// Target with DO UPDATE
builder.insert(user).values([InsertUser::new("Alice")])
    .on_conflict(user.email).do_update(UpdateUser::default().with_name("updated"));
}
Source

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

Shorthand for ON CONFLICT DO NOTHING without specifying a target.

This matches any constraint violation.

Source

pub fn returning<Columns>( 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: ToSQL<'a, SQLiteValue<'a>> + IntoSelectTarget, Columns::Marker: ResolveRow<T>,

Adds a RETURNING clause and transitions to ReturningSet state

Source§

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

Source

pub fn returning<Columns>( 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: ToSQL<'a, SQLiteValue<'a>> + IntoSelectTarget, Columns::Marker: ResolveRow<T>,

Adds a RETURNING clause after ON CONFLICT

Source§

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

Source

pub fn where<E>( self, condition: E, ) -> InsertBuilder<'a, S, InsertOnConflictSet, T>
where E: Expr<'a, SQLiteValue<'a>>, E::SQLType: BooleanLike,

Adds a WHERE clause to the DO UPDATE SET clause.

Generates: ON CONFLICT (col) DO UPDATE SET ... WHERE condition

Source

pub fn returning<Columns>( 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: ToSQL<'a, SQLiteValue<'a>> + IntoSelectTarget, Columns::Marker: ResolveRow<T>,

Adds a RETURNING clause 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, Scoped<M, Cons<T, Nil>>, <M as ResolveRow<T>>::Row>
where T: ToSQL<'a, SQLiteValue<'a>>, M: ResolveRow<T>,

Specifies the table or subquery to select FROM.

This method transitions the builder from the initial state to the FROM state, enabling subsequent WHERE, JOIN, ORDER BY, and other clauses.

The row type R is resolved from the select marker M and the table T via the ResolveRow trait.

§Examples
// Select from a table
let query = builder.select(user.name).from(user);
assert_eq!(query.to_sql().sql(), r#"SELECT "users"."name" FROM "users""#);
Source§

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

Source

pub fn join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterJoin<R, J::JoinedTable>>::NewRow, G>

Adds an INNER JOIN clause to the query.

Joins another table to the current query using the specified condition. The joined table must be part of the schema and the condition should relate columns from both tables.

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

pub fn natural_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn natural_left_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterLeftJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn left_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterLeftJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn left_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterLeftJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn natural_left_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterLeftJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn natural_right_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterRightJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn right_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterRightJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn right_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterRightJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn natural_right_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterRightJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn natural_full_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterFullJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn full_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterFullJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn full_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterFullJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn natural_full_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterFullJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn inner_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterJoin<R, J::JoinedTable>>::NewRow, G>

Source

pub fn cross_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterJoin<R, J::JoinedTable>>::NewRow, G>

Source§

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

Source

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

Adds a WHERE clause to filter query results.

// Single condition
let query = builder
    .select(user.name)
    .from(user)
    .r#where(gt(user.id, 10));
assert_eq!(
    query.to_sql().sql(),
    r#"SELECT "users"."name" FROM "users" WHERE "users"."id" > ?"#
);

// Multiple conditions
let query = builder
    .select(user.name)
    .from(user)
    .r#where(and(gt(user.id, 10), eq(user.name, "Alice")));
Source§

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

Source

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

Adds a GROUP BY clause to the query.

Source§

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

Source

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

Adds a HAVING clause after GROUP BY.

Source§

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

Source

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

Sorts the query results.

Source§

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

Source

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

Limits the number of rows returned.

§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: OffsetAllowed,

Source

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

Sets the offset for the query results.

§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: AsCteState, T: SQLTable<'a, SQLiteSchemaType, SQLiteValue<'a>>,

Source

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

Converts this SELECT query into a typed CTE using alias tag name.

Source§

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

Source

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

Combines this query with another using UNION.

Source

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

Combines this query with another using UNION ALL.

Source

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

Combines this query with another using INTERSECT.

Source

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

Combines this query with another using INTERSECT ALL.

Source

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

Combines this query with another using EXCEPT.

Source

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

Combines this query with another using EXCEPT ALL.

Source§

impl<'a, Schema, Table> QueryBuilder<'a, Schema, UpdateInitial, Table>
where Table: SQLiteTable<'a>,

Source

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

Specifies which columns to update and their new values.

This method accepts update expressions that specify which columns should be modified. You can update single or multiple columns using the generated update model’s with_* setters.

§Examples
// Update single column
let query = builder
    .update(user)
    .set(UpdateUser::default().with_name("New Name"));
assert_eq!(query.to_sql().sql(), r#"UPDATE "users" SET "name" = ?"#);

// Update multiple columns
let query = builder
    .update(user)
    .set(UpdateUser::default().with_name("New Name").with_email("new@example.com"));
Source§

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

Source

pub fn where<E>(self, condition: E) -> UpdateBuilder<'a, S, UpdateWhereSet, T>
where E: Expr<'a, SQLiteValue<'a>>, E::SQLType: BooleanLike,

Adds a WHERE clause to specify which rows to update.

Without a WHERE clause, all rows in the table would be updated. This method allows you to specify conditions to limit which rows are affected by the update.

§Examples
// Update specific row by ID
let query = builder
    .update(user)
    .set(UpdateUser::default().with_name("Updated Name"))
    .r#where(eq(user.id, 1));
assert_eq!(
    query.to_sql().sql(),
    r#"UPDATE "users" SET "name" = ? WHERE "users"."id" = ?"#
);

// Update multiple rows with complex condition
let query = builder
    .update(user)
    .set(UpdateUser::default().with_name("Updated"))
    .r#where(and(gt(user.id, 10), eq(user.age, 25)));
Source

pub fn returning<Columns>( 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: ToSQL<'a, SQLiteValue<'a>> + IntoSelectTarget, Columns::Marker: ResolveRow<T>,

Adds a RETURNING clause and transitions to the ReturningSet state

Source§

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

Source

pub fn returning<Columns>( 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: ToSQL<'a, SQLiteValue<'a>> + IntoSelectTarget, Columns::Marker: ResolveRow<T>,

Adds a RETURNING clause 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

Attaches a sqlcommenter comment to the query.

The comment is prepended to the generated SQL and wrapped in /* ... */. Any /* or */ sequences in the input are sanitised so they can’t terminate the surrounding comment.

Source

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

Attaches a tag-style sqlcommenter comment to the query.

Each (key, value) pair is URL-encoded, sorted alphabetically, joined with ,, and wrapped in /* ... */. Pairs with empty values are skipped; an all-empty input is a no-op.

Source§

impl<'a> QueryBuilder<'a>

Source

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

Creates a new query builder for the given schema type.

This is the entry point for building SQL queries. The schema type parameter ensures that only valid tables from your schema can be used in queries.

§Examples
use drizzle::sqlite::prelude::*;
use drizzle::sqlite::builder::QueryBuilder;

#[SQLiteTable(name = "users")]
struct User {
    #[column(primary)]
    id: i32,
    name: String,
}

#[derive(SQLiteSchema)]
struct MySchema {
    user: User,
}

let builder = QueryBuilder::new::<MySchema>();
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, SQLiteValue<'a>> + IntoSelectTarget,

Begins a SELECT query with the specified columns.

This method starts building a SELECT statement. You can select individual columns, multiple columns as a tuple, or use () to select all columns.

§Examples
// Select a single column
let query = builder.select(user.name).from(user);
assert_eq!(query.to_sql().sql(), r#"SELECT "users"."name" FROM "users""#);

// Select multiple columns
let query = builder.select((user.id, user.name)).from(user);
assert_eq!(query.to_sql().sql(), r#"SELECT "users"."id", "users"."name" FROM "users""#);
Source

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

Begins a SELECT DISTINCT query with the specified columns.

SELECT DISTINCT removes duplicate rows from the result set.

§Examples
let query = builder.select_distinct(user.name).from(user);
assert_eq!(query.to_sql().sql(), r#"SELECT DISTINCT "users"."name" FROM "users""#);
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, SQLiteValue<'a>> + IntoSelectTarget,

Source

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

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

Source

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

Begins an INSERT query after a CTE.

Source

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

Begins an UPDATE query after a CTE.

Source

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

Begins a DELETE query after a CTE.

Source

pub fn with<C>(&self, cte: &C) -> Self
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: SQLiteTable<'a>,

Begins an INSERT query for the specified table.

This method starts building an INSERT statement. The table must be part of the schema and will be type-checked at compile time.

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

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

Begins an UPDATE query for the specified table.

This method starts building an UPDATE statement. The table must be part of the schema and will be type-checked at compile time.

§Examples
let query = builder
    .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" = ? WHERE "users"."id" = ?"#);
Source

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

Begins a DELETE query for the specified table.

This method starts building a DELETE statement. The table must be part of the schema and will be type-checked at compile time.

§Examples
let query = builder
    .delete(user)
    .r#where(lt(user.id, 10));
assert_eq!(query.to_sql().sql(), r#"DELETE FROM "users" WHERE "users"."id" < ?"#);
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, Marker: Clone, Row: Clone, Grouped: Clone> Clone for QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>

Source§

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

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() -> QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>

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

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

Source§

fn to_sql(&self) -> SQL<'a, SQLiteValue<'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.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<'a, Schema, State, Table, Marker, Row, Grouped> UnsafeUnpin 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>
where Schema: UnwindSafe, State: UnwindSafe, Table: UnwindSafe, Marker: UnwindSafe, Row: UnwindSafe, Grouped: UnwindSafe,

Blanket Implementations§

Source§

impl<T> AliasExt for T

Source§

fn alias(self, name: &'static str) -> AliasedExpr<Self>

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

Source§

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

Source§

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

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 AggOr<<R as ComparisonOperand<'a, V, Self>>::Aggregate>>::Output>
where R: ComparisonOperand<'a, V, Self>, Self::SQLType: Compatible<<R as ComparisonOperand<'a, V, Self>>::SQLType>, Self::Aggregate: AggOr<<R as ComparisonOperand<'a, V, Self>>::Aggregate>,

Equality comparison (=). Read more
Source§

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

Inequality comparison (<>). Read more
Source§

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

Greater-than comparison (>). Read more
Source§

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

Greater-than-or-equal comparison (>=). Read more
Source§

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

Less-than comparison (<). Read more
Source§

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

Less-than-or-equal comparison (<=). Read more
Source§

fn like<R>( self, pattern: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggOr<<R as ComparisonOperand<'a, V, Self>>::Aggregate>>::Output>
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, Self::Aggregate: AggOr<<R as ComparisonOperand<'a, V, Self>>::Aggregate>,

LIKE pattern matching. Read more
Source§

fn not_like<R>( self, pattern: R, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <Self::Aggregate as AggOr<<R as ComparisonOperand<'a, V, Self>>::Aggregate>>::Output>
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, Self::Aggregate: AggOr<<R as ComparisonOperand<'a, V, Self>>::Aggregate>,

NOT LIKE pattern matching. Read more
Source§

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

IS NULL check. Read more
Source§

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

IS NOT NULL check. Read more
Source§

fn between<L, H>( self, low: L, high: H, ) -> SQLExpr<'a, V, <<V as SQLParam>::DialectMarker as DialectTypes>::Bool, NonNull, <<Self::Aggregate as AggOr<<L as ComparisonOperand<'a, V, Self>>::Aggregate>>::Output as AggOr<<H as ComparisonOperand<'a, V, Self>>::Aggregate>>::Output>
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>, Self::Aggregate: AggOr<<L as ComparisonOperand<'a, V, Self>>::Aggregate>, <Self::Aggregate as AggOr<<L as ComparisonOperand<'a, V, Self>>::Aggregate>>::Output: AggOr<<H as ComparisonOperand<'a, V, Self>>::Aggregate>,

BETWEEN comparison. Read more
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 AggOr<<L as ComparisonOperand<'a, V, Self>>::Aggregate>>::Output as AggOr<<H as ComparisonOperand<'a, V, Self>>::Aggregate>>::Output>
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>, Self::Aggregate: AggOr<<L as ComparisonOperand<'a, V, Self>>::Aggregate>, <Self::Aggregate as AggOr<<L as ComparisonOperand<'a, V, Self>>::Aggregate>>::Output: AggOr<<H as ComparisonOperand<'a, V, Self>>::Aggregate>,

NOT BETWEEN comparison. Read more
Source§

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

IN array check. Read more
Source§

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

NOT IN array check. Read more
Source§

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

IN subquery check.
Source§

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

NOT IN subquery check.
Source§

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

IS DISTINCT FROM - NULL-safe inequality comparison. Read more
Source§

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

IS NOT DISTINCT FROM - NULL-safe equality comparison. Read more
Source§

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

IS TRUE - boolean test that handles NULL. Read more
Source§

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

IS FALSE - boolean test that handles NULL. 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<Mk> MarkerAggValidFor<()> for Mk

Source§

impl<Scope> ScopeSatisfies<Nil, ()> for Scope

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

impl<T> TypeEq<T> for T