Expand description
Raw SQL execution helpers. Raw SQL execution helpers for SQL backends.
Use [statement] for SQL that returns an affected-row count and query
for SQL that returns rows. Both builders execute through
Executor, so they work with Db,
Connection, and Transaction.
Raw SQL is backend SQL. Toasty does not rewrite placeholders, quote
identifiers, or hydrate models from raw query results. Use the placeholder
syntax of the active driver. The syntax is exposed at runtime through
Capability::sql_placeholder:
| Backend | SqlPlaceholder |
|---|---|
| SQLite | NumberedQuestionMark (?1, ?2, …) |
| Turso | NumberedQuestionMark (?1, ?2, …) |
| PostgreSQL | DollarNumber ($1, $2, …) |
| MySQL | QuestionMark (?, ?, …) |
§Statements
let updated = toasty::sql::statement(
"UPDATE users SET name = ?1 WHERE id = ?2",
)
.bind("Alice")
.bind(1_i64)
.exec(&mut db)
.await?;
assert_eq!(updated, 1);§Queries
Queries return dynamic [Value] rows. Each row is a [Value::Record] with
fields in selected-column order.
let rows = toasty::sql::query(
"SELECT id, name FROM users WHERE active = ?1",
)
.bind(true)
.exec(&mut db)
.await?;The driver infers result value types from database metadata by default. Use
[Query::column_types] when a result column is ambiguous, such as a SQLite
boolean stored as an integer or a UUID stored as bytes.
Structs§
- Query
- A raw SQL query that returns dynamic rows.
- Statement
- A raw SQL statement that returns an affected-row count.