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 the validated SQL as a &'static str literal.
§Syntax
ⓘ
let sql = query!("SELECT id, name FROM users WHERE id = ?");§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