query!() { /* proc-macro */ }Expand description
Compile-time SQL validation with optional real DB verification.
Behavior:
- Always runs the same syntax validation as
sql_string!. - When the
db-verifycargo feature is enabled AND theSZ_ORM_QUERY_VERIFY=1environment variable is set at compile time, connects to the database pointed to byDATABASE_URLand runsEXPLAIN(MySQL/PostgreSQL) orEXPLAIN QUERY PLAN(SQLite) to verify the SQL is valid against the actual schema (column names, table names, joins, etc.). - Otherwise, falls back to syntax-only validation.
Emits a [sz_orm_core::queryable::Query] object wrapping the validated SQL.
§Syntax
ⓘ
use sz_orm_core::queryable::Query;
let q = query!("SELECT id, name FROM users WHERE id = ?");
let rows = q.fetch_all(&mut conn).await?;§Verification setup
export DATABASE_URL="mysql://user:pass@host:3306/db"
export SZ_ORM_QUERY_VERIFY=1
cargo build --features sz-orm-macros/db-verify