2 unstable releases

0.2.0 Sep 5, 2024
0.1.0 Aug 28, 2024

#2463 in Database interfaces

Download history 123/week @ 2024-08-25 131/week @ 2024-09-01 5/week @ 2024-09-08 27/week @ 2024-09-15 15/week @ 2024-09-22 45/week @ 2024-09-29

105 downloads per month

MIT/Apache

46KB
309 lines

sqly github.com crates.io docs.rs

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.2.0"
features = ["postgres"]

[dependencies.sqlx]
version = "0.8.0"
default-features = false
features = ["macros", "postgres"]

[profile.dev.package.sqlx-macros]
opt-level = 3

[profile.dev.package.sqly-macros]
opt-level = 3
Features

unchecked — disable compile-time checking
postgres — generate queries for PostgreSQL
sqlite — generate queries for SQLite (not supported)
mysql — generate queries for MySQL (not supported)

Currently only postgres is supported.


Usage

docs.rs


Roadmap

  • Basic DELETE queries
  • Basic INSERT queries
  • Basic UPDATE queries
  • Storing information across separate #[derive] invocations
  • Basic SELECT queries
  • sqly::query! macros to extend generated queries
  • #[sqly(alias)] attribute and optional override in macros
  • #[sqly(default, from, try_from, flatten)] attributes for select
  • #[sqly(optional)] attribute for optional update and insert fields
  • #[sqly(returning)] attribute for generating SQL RETURNING clauses
  • #[sqly(foreign)] attributes for nested objects through SQL JOIN clauses
  • Support for decoding database rows unchecked or by index
  • Implementation of bulk operations for &[T]
  • Support for SQL DISTINCT clause in select
  • Support for including constants in the SQL
  • Support for filtering on nullable columns
  • Support for foreign macro attributes
  • Support for generics
  • ... ?

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

~8–22MB
~337K SLoC