https://github.com/lmoors30/sqly
A lightweight macro system on top of sqlx, inspired by ormx.
https://github.com/lmoors30/sqly
async await postgres rust sql
Last synced: 2 months ago
JSON representation
A lightweight macro system on top of sqlx, inspired by ormx.
- Host: GitHub
- URL: https://github.com/lmoors30/sqly
- Owner: LMOORS30
- License: apache-2.0
- Created: 2024-08-28T12:38:59.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-26T10:58:54.000Z (over 1 year ago)
- Last Synced: 2025-04-08T20:47:19.051Z (12 months ago)
- Topics: async, await, postgres, rust, sql
- Language: Rust
- Homepage:
- Size: 98.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
sqly
[
](https://github.com/LMOORS30/sqly)
[
](https://crates.io/crates/sqly)
[
](https://docs.rs/sqly)
====
sqly is a lightweight macro system on top of [sqlx](https://github.com/launchbadge/sqlx), inspired by [ormx](https://github.com/NyxCode/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 by the added functionality of generating SQL `SELECT` queries with support for nested objects through SQL `JOIN` clauses. Additionally, many more attributes are available to further customize the query generation and row decoding.
##### Cargo.toml
```toml
[dependencies.sqly]
version = "0.5.0"
features = ["postgres"]
[dependencies.sqlx]
version = "0.8.6"
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
[
](https://docs.rs/sqly)
### Roadmap
**Major**
- [X] Basic `DELETE` queries
- [X] Basic `INSERT` queries
- [X] Basic `UPDATE` queries
- [X] Basic `SELECT` queries
- [X] Storing information across separate `#[derive]` invocations
- [ ] Optional outer macro pattern for better compiler support
- [X] `#[sqly(foreign)]`
- [X] SQL `INNER JOIN`
- [X] SQL `LEFT JOIN`
- [X] Custom SQL joins
- [X] Unique table aliases
- [ ] `sqly::query!` macros to extend generated queries
**Minor**
- [X] `Flat::Flat` type for flexibility
- [X] `#[sqly(infer)]` for custom sqlx types
- [X] `#[sqly(value)]` for custom parameter binding
- [X] `#[sqly(select)]` for custom SQL select expressions
- [X] `#[sqly(default, from, try_from)]` for decoding table fields
- [X] `#[sqly(insert, update)]` for custom SQL value expressions
- [X] `#[sqly(filter)]` for custom SQL filter expressions
- [X] `#[sqly(optional)]` for dynamic SQL through optional fields
- [X] `#[sqly(returning)]` for SQL `RETURNING` clause
**Draft**
- [ ] `#[sqly(flatten)]` for nested structs
- [ ] `#[sqly(group)]` for SQL `GROUP BY` clause
- [ ] `#[sqly(distinct, order, limit, offset)]` clauses
- [ ] Decoding database rows unchecked or by index
- [ ] Custom attributes in generated structs
- [ ] Support for generic structs
- [ ] Output dummy code on error
- [ ] ... ?
#### 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.