Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Easy SQL
Easy SQL is a macro-first toolkit for writing SQL with strong compile-time guarantees. Based on sqlx
- Readable SQL with IDE syntax highlighting (VS Code) inside
query!andquery_lazy!. - Type-checked column and table references, plus bind validation via
{value}. - Clean bindings embedded directly into the macro input, no separate
bind()chain. - Optional migrations see #Migration system.
- Optional table name checks to prevent duplicates across files.
- Interoperable with
sqlx: useeasy-sqlmacros on SQLx connections/pools, or use migrations only. - Currently supported drivers: SQLite and Postgres.
Installation
Add the easy-sql dependency, then choose drivers and the matching sqlx runtime/TLS features.
1) Add easy-sql
Pick the driver features you need. Checking for duplicate table names is enabled by default. See Feature flags
[]
= { = "0.100", = ["sqlite", "postgres"] }
2) Add sqlx with runtime + TLS + driver
SQLx requires choosing one runtime and optionally one TLS backend, plus your database driver(s). From the official SQLx install guide:
- Runtime:
runtime-tokioorruntime-async-std. - TLS: (optional)
tls-native-tlsor one of thetls-rustls-*variants. - SQLite: choose
sqlite(bundled SQLite) orsqlite-unbundled(system SQLite).
Example using Tokio + Rustls + SQLite:
[]
= { = "0.8", = ["runtime-tokio", "tls-rustls-ring-webpki", "sqlite"] }
See the full SQLx installation matrix at https://github.com/launchbadge/sqlx#install.
3) Add the build helper (optional but recommended)
The build helper crate is easy-sql-build.
Use it when you want:
- to not provide
#[sql(drivers = ...)]for every Table by hand, - specific driver compatibility checks
- migrations,
- duplicate table name checks (
check_duplicate_table_names), - default drivers for
query_lazy!.
Add it as a build dependency:
[]
= "1"
= "1" # needed only when you want to ignore certain files/directories in the build script
Example build.rs:
⚠️ Do not gitignore
easy_sql.ron. It stores migration metadata + selected default drivers + list of all table names.
Query macros
query! and query_lazy! give you readable SQL with compile-time validation and typed outputs.
query!executes immediately and returns ananyhow::Result<Output>.query_lazy!builds a lazy query and returns a stream on execution. Withuse_output_columnsfeature, bare column references are referring to columns from the output type, instead of the table type.
Mini demo
use Database;
use ;
// DatabaseSetup lets you group tables into a single setup call.
// Required to make sure that no fields are potentially ignored
async
Migration system
Migrations are optional and driven by table versions in Table definitions. Use migrations feature to enable them.
- Create the table struct and set
#[sql(version = 1)]. - Save/build so the build helper can generate
#[sql(unique_id = "...")]and register the version structure ineasy_sql.ron. - Update the table (add/rename fields), then bump the version up.
- Save/build again — the migration from version 1 is automatically generated and will be applied when (driver related)
Database::setupor (table related)DatabaseSetup::setupare called.
Version tracking is stored in EasySqlTables, and you can opt out with #[sql(no_version)] (needed only when migrations feature is enabled).
Feature highlights (not everything)
table_join!for typed joins.custom_sql_function!for custom SQL functions.IN {vec}binding with automatic placeholder expansion.#[sql(select = ...)]onOutputfields.#[sql(bytes)]for binary/serde storage.- Composite primary keys and
#[sql(foreign_key = ...)]relationships.
Feature flags
Each feature below is toggled on easy-sql (not on SQLx). Defaults are noted.
| Feature | Default | Description |
|---|---|---|
sqlite |
❌ | Enable the SQLite driver. |
postgres |
❌ | Enable the Postgres driver. |
sqlite_math |
❌ | Enable extra SQLite math functions. Sqlite needs to be compiled with LIBSQLITE3_FLAGS="-DSQLITE_ENABLE_MATH_FUNCTIONS" for those functions to work |
migrations |
❌ | Enable migration generation and tracking. |
check_duplicate_table_names |
✅ | Detect duplicate table names at build time. |
use_output_columns |
❌ | Bare columns refer to output the type, instead of the table type. |
bigdecimal |
❌ | Add BigDecimal ToDefault support (SQLx bigdecimal). |
rust_decimal |
❌ | Add Decimal ToDefault support (SQLx rust_decimal). |
uuid |
❌ | Add Uuid ToDefault support via SQLx. |
chrono |
❌ | Add chrono ToDefault support via SQLx. |
ipnet |
❌ | Add ipnet ToDefault support via SQLx. |
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.