query!() { /* proc-macro */ }Expand description
编译时 SQL 校验 + 可选真实 DB 验证宏 — 复用自 sz-orm-macros
与 sql_string! 行为一致,额外支持在 db-verify feature 启用且
SZ_ORM_QUERY_VERIFY=1 环境变量设置时,连接 DATABASE_URL 指向的
数据库执行 EXPLAIN 进行真实 schema 校验。
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