| Crates.io | sql-check_derive |
| lib.rs | sql-check_derive |
| version | 0.9.0-alpha.1 |
| created_at | 2026-01-21 10:12:09.604508+00 |
| updated_at | 2026-01-21 10:12:09.604508+00 |
| description | Procedural macro for SQL Check. Do not use directly, use sql-check crate instead. |
| homepage | |
| repository | https://github.com/tamaro-skaljic/sql-check |
| max_upload_size | |
| id | 2058786 |
| size | 81,398 |
Compile-time SQL validation extracted from SQLx.
This crate provides a check! macro that validates SQL queries at compile time by connecting to a database and ensuring the query is valid.
Add sql-check to your Cargo.toml:
[dependencies]
sql-check = "0.9.0-alpha.1"
# Enable database support
sql-check = { version = "0.9.0-alpha.1", features = ["postgres"] }
use sql_check::check;
// This will be validated at compile time
let sql = check!("SELECT * FROM users WHERE id = 1");
// Use the SQL string with your database library
let result = database.execute(sql).await?;
check (default): Enables compile-time SQL validation
postgres: PostgreSQL supportmysql: MySQL supportsqlite: SQLite support_rt-tokio: Use Tokio runtime (recommended)_rt-async-std: Use async-std runtime_rt-smol: Use smol runtime_rt-async-global-executor: Use async-global-executor runtime_tls-rustls-ring-webpki: Use rustls with ring and webpki_tls-rustls-aws-lc-rs: Use rustls with AWS-LC_tls-rustls-ring-native-roots: Use rustls with ring and native roots_tls-native-tls: Use native-tls[dependencies]
sql-check = {
version = "0.9.0-alpha.1",
features = ["postgres", "_rt-tokio", "_tls-rustls-ring-webpki"]
}
The macro requires the following environment variables:
DATABASE_URL: Connection string for your database
postgres://user:pass@host/dbmysql://user:pass@host/dbsqlite://path/to/db.sqlite# Set DATABASE_URL before building
export DATABASE_URL="postgres://user:pass@localhost/mydb"
cargo build
For CI/CD pipelines, production builds, or when you don't have a database connection, disable the check feature:
[dependencies]
sql-check = { version = "0.9.0-alpha.1", default-features = false }
Or use cargo build flags:
cargo build --release --no-default-features
let sql = check!("SELECT invalid_column FROM nonexistent_table");
Compile Error:
error: SQL validation failed: relation "nonexistent_table" does not exist
--> src/main.rs:5:15
|
5 | let sql = check!("SELECT invalid_column FROM nonexistent_table");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Feature | sql-check check! |
SQLx query! |
|---|---|---|
| SQL Validation | ✅ | ✅ |
| Type Checking | ❌ | ✅ |
| Returns | SQL String | Typed Query |
| Use Case | Pre-validation | Full ORM |
The check! macro is ideal when you:
Licensed under either of
at your option.
This crate is extracted from SQLx. Contributions are welcome!