query_as!() { /* proc-macro */ }Expand description
Compile-time SQL schema generator.
Parses a SQL CREATE TABLE statement and generates typed table declarations
equivalent to typed_query! { table ... }.
§Syntax
use sz_orm_macros::schema;
schema! {
"CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT)"
}Generates code equivalent to the following manual declaration:
typed_query! {
table users {
id: i64,
name: String,
email: Option<String>,
}
}Typed raw SQL query macro (SQLx query_as! style).
Usage: query_as!(RecordType, "SELECT col1, col2 FROM table WHERE id = ?")
Generates sz_orm_core::queryable::QueryAs::<RecordType>::new("SELECT ...").
When the db-verify feature + SZ_ORM_QUERY_VERIFY=1 is set, connects to the real DB
and runs EXPLAIN to verify SQL validity.
Runtime column-name validation (P0-2): QueryAs::fetch_all compares the column names
returned by the DB against RecordType::row_desc() (auto-generated by #[derive(FromQueryResult)]).
If a SELECT column is not among the struct fields, returns DbError::QueryError.
§Example
#[derive(FromQueryResult)]
struct User { id: i64, name: String }
let q = query_as!(User, "SELECT id, name FROM users WHERE id = 1");
let users: Vec<User> = q.fetch_all(&mut conn).await?;