pub type DeleteBuilder<'a, Schema, State, Table> = QueryBuilder<'a, Schema, State, Table>;Expand description
Builds a DELETE query specifically for SQLite.
DeleteBuilder provides a type-safe, fluent API for constructing DELETE statements
with support for conditional deletions and returning clauses.
§Type Parameters
Schema: The database schema type, ensuring only valid tables can be referencedState: The current builder state, enforcing proper query construction orderTable: The table being deleted from
§Query Building Flow
- Start with
QueryBuilder::delete(table)to specify the target table - Optionally add
where()to specify which rows to delete - Optionally add
returning()to get deleted values back
§Basic Usage
use drizzle::sqlite::prelude::*;
use drizzle::core::expr::{eq, lt};
use drizzle::sqlite::builder::QueryBuilder;
#[SQLiteTable(name = "users")]
struct User {
#[column(primary)]
id: i32,
name: String,
email: Option<String>,
}
#[derive(SQLiteSchema)]
struct Schema {
user: User,
}
let builder = QueryBuilder::new::<Schema>();
let Schema { user } = Schema::new();
// Delete specific row
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 multiple rows
let query = builder
.delete(user)
.r#where(lt(user.id, 100));
assert_eq!(query.to_sql().sql(), r#"DELETE FROM "users" WHERE "users"."id" < ?"#);§Advanced Deletions
§DELETE with RETURNING
let query = builder
.delete(user)
.r#where(eq(user.id, 1))
.returning((user.id, user.name));
assert_eq!(
query.to_sql().sql(),
r#"DELETE FROM "users" WHERE "users"."id" = ? RETURNING "users"."id", "users"."name""#
);§DELETE all rows (use with caution!)
// This deletes ALL rows - be careful!
let query = builder.delete(log);
assert_eq!(query.to_sql().sql(), r#"DELETE FROM "logs""#);Aliased Type§
pub struct DeleteBuilder<'a, Schema, State, Table> {
pub sql: SQL<'a, SQLiteValue<'a>>,
/* private fields */
}Fields§
§sql: SQL<'a, SQLiteValue<'a>>Implementations§
Source§impl<'a, S, T> DeleteBuilder<'a, S, DeleteInitial, T>
impl<'a, S, T> DeleteBuilder<'a, S, DeleteInitial, T>
Sourcepub fn where(
self,
condition: impl ToSQL<'a, SQLiteValue<'a>>,
) -> DeleteBuilder<'a, S, DeleteWhereSet, T>
pub fn where( self, condition: impl ToSQL<'a, SQLiteValue<'a>>, ) -> DeleteBuilder<'a, S, DeleteWhereSet, T>
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)])
]));Sourcepub fn returning(
self,
columns: impl ToSQL<'a, SQLiteValue<'a>>,
) -> DeleteBuilder<'a, S, DeleteReturningSet, T>
pub fn returning( self, columns: impl ToSQL<'a, SQLiteValue<'a>>, ) -> DeleteBuilder<'a, S, DeleteReturningSet, T>
Adds a RETURNING clause to the query
Source§impl<'a, S, T> DeleteBuilder<'a, S, DeleteWhereSet, T>
impl<'a, S, T> DeleteBuilder<'a, S, DeleteWhereSet, T>
Sourcepub fn returning(
self,
columns: impl ToSQL<'a, SQLiteValue<'a>>,
) -> DeleteBuilder<'a, S, DeleteReturningSet, T>
pub fn returning( self, columns: impl ToSQL<'a, SQLiteValue<'a>>, ) -> DeleteBuilder<'a, S, DeleteReturningSet, T>
Adds a RETURNING clause after WHERE