| Crates.io | sqlb |
| lib.rs | sqlb |
| version | 0.5.0-alpha.1 |
| created_at | 2021-09-09 04:57:33.940375+00 |
| updated_at | 2023-09-26 21:59:49.406272+00 |
| description | Simple, expressive, and progressive SQL Builder for Rust. |
| homepage | https://github.com/jeremychone/rust-sqlb |
| repository | https://github.com/jeremychone/rust-sqlb |
| max_upload_size | |
| id | 448717 |
| size | 33,635 |
sqlx anymore (no sqlx dependencies)sea-query alternative solution, it now adds on top of sea-queryThe result is a bit more verbose, but it takes full advantage of sea-query:
postgres/tokio-postgres, rusqlite, sqlx/* diesel/*)So, sqlb just adds the missing mile:
HasFields trait on struct, to provide a list of columns, and columns/values for struct instance.#[derive(Fields)] proc derive macro to implement HasFieldsfields.zip() and fields.unzip() to conveniently transform a field list to the columns/values expected by sea-query query builders.And more to come.
See Rust web-app production code blueprint on rust10x.com for an example of how this is used in a production code envornement
#[Derive(sqlb::Fields)]// sqlb::Fields
#[derive(sqlb::Fields, Debug, Default)]
struct TodoForCreate {
title: String,
done: Option<bool>, // if None, not set, so db default (false)
#[field(name = "description")]
desc: Option<String>, // if None, not set, so db default (false)
}
| Function/Method | Returns |
|---|---|
TodoForCreate::field_names() |
["title", "done", "description"] |
TodoForCreate::field_idens() |
Vec<sea_query::DynIden> (for sea-query select) |
todo_object.all_fields() |
Fields object allowing the following |
fields.zip() |
(Vec<DynIden>, Vec<SimpleExpr>) for sea-query insert |
fields.unzip() |
Iterator of (DynIden, SimpleExpr) for sea-query update |
fields.push(Field::new(...)) |
To add dynamic name/value to be inserted/updated |
cargo run -p example-tokio-postgres
cargo run -p example-sqlx-postgres
Note: Currently,
sqlbis completely DB-unaware, meaning that the examples provided above could be adapted to MySQL or SQLite by simply changing the DB Driver and Sea-Query binding dependency. For reference, see sea-query examples.
! breaking change, ^ enhancement, + addition, - fix.
0.5.0-alpha.x FULL REWRITE AND DIFFERENT STRATEGY - SEA-QUERY based now0.4.0 - 2023-11-21
^ Updated to sqlx 0.70.3.3 .. 0.3.8 - 2023-08-03
+ generic types for bindable! macro. PR from KaiserBh+ chrono binding under the feature chrono_support. PR from KaiserBh0.3.2 .. 0.3.7
+ Add support for partial and fully qualified table and column names. #8+ Add SqlxBindable blanket implementation for Option<T>. #7+ Add .limit(..) and .offset(..) for Select.+ Add .count() for Select.+ Add #[field(skip)] and #[field(name="other_name")] to skip or rename properties.0.3.1
! BREAKING CHANGE - HasFields.fields has been rename to HasFields.not_none_fields().! BREAKING CHANGE - HasFields.not_none_fields() and HasFields.all_fields() consume the self (to avoid uncessary clone).+ - HasFields.all_fields() - returns all fields (even the one where value are None).+ - HasFields::field_names(): &'static [&'static] - list of field names (i.e., column names).+ - Added SqlxBindable for the Option<T> (not a blanket impl at this point).0.3.0 been deprecated since did not have the ...fields(self) behavior.0.2.0
sqlx. From .fetch_one::<(i64, String), _> to .fetch_one::<_, (i64, String)>0.0.7
sqlb::insert().table("todo") (in 0.0.7) rather than sqlb::insert("toto") (<=0.0.6) (for all SqlBuilders)
Start a PostgreSQL
# In terminal 1 - start postges
docker run --rm --name pg -p 5432:5432 -e POSTGRES_PASSWORD=welcome postgres:15
# In terminal 2 - (optional) launch psql on the Postgres instance above
docker exec -it -u postgres pg psql
# In terminal 3 -
cargo test
# or watch a particular test target
cargo watch -q -c -x 'test --test test_sb_insert