5 releases (3 breaking)
0.4.0 | Apr 10, 2025 |
---|---|
0.3.1 | Dec 26, 2024 |
0.3.0 | Oct 17, 2024 |
0.2.0 | Sep 5, 2024 |
0.1.0 | Aug 28, 2024 |
#2839 in Procedural macros
187 downloads per month
Used in sqly
190KB
5K
SLoC
sqly

sqly is a lightweight macro system on top of sqlx, inspired by ormx.
It works by generating common SQL queries and associated structs at compile time, letting the generated queries be checked and executed by sqlx.
This crate differs from ormx mainly by the added functionality of generating SQL SELECT
queries with support for nested objects through SQL JOIN
clauses. Additionally, sqly::query!
macros can be used to further expand generated queries while still providing compile-time verification.
This functionality is still under development (see Roadmap).
Cargo.toml
[dependencies.sqly]
version = "0.4.0"
features = ["postgres"]
[dependencies.sqlx]
version = "0.8.0"
default-features = false
[profile.dev.package.sqlx-macros]
opt-level = 3
[profile.dev.package.sqly-macros]
opt-level = 3
Features
postgres
— generate queries for PostgreSQL
mariadb
— generate queries for MariaDB (not supported)
sqlite
— generate queries for SQLite (not supported)
mysql
— generate queries for MySQL (not supported)
checked
— enable compile-time checking (default)
Currently only postgres is supported.
Usage
Roadmap
Major
- Basic
DELETE
queries - Basic
INSERT
queries - Basic
UPDATE
queries - Basic
SELECT
queries- Storing information across separate
#[derive]
invocations - Optional outer macro pattern for better compiler support
- Storing information across separate
-
#[sqly(foreign)]
- SQL
INNER JOIN
- SQL
LEFT JOIN
- Custom SQL joins
- Unique table aliases
- SQL
-
sqly::query!
macros to extend generated queries
Minor
-
Flat::Flat
type for flexibility -
#[sqly(infer)]
for custom sqlx types -
#[sqly(value)]
for custom parameter binding -
#[sqly(select)]
for custom SQL select expressions -
#[sqly(default, from)]
for decoding table fields -
#[sqly(insert, update)]
for custom SQL value expressions -
#[sqly(filter)]
for custom SQL filter expressions -
#[sqly(optional)]
for dynamic SQL through optional fields -
#[sqly(returning)]
for SQLRETURNING
clause
Draft
-
#[sqly(group)]
for SQLGROUP BY
clause -
#[sqly(distinct, order, limit, offset)]
clauses - Decoding database rows unchecked or by index
- Custom attributes in generated structs
- Support for generic structs
- ... ?
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies
~0.5–1MB
~23K SLoC