IMPORTANT - 0.0.x versions will be experimental and probably break APIs in each release.
sqlb is (will be) a simple and expressive SQLBuilder for Rust.
- Simple - Focused on providing an expressive, composable, and reasonnably typed scheme to build and execute (via sqlx for now) parameterized SQL statements. The goal is NOT to abstract SQL but to make it expressive and composable using Rust programmatic constructs.
- NOT a database executor/driver (Will be using SQLX as sql executore)
- NOT an ORM, although eventually, one could build an ORM on top of it.
- Expressive - From arbitrary typed data in and out (list of names/values) to struct and mapping rules.
- Focused
- Prepared Statement ONLY!
NOTE: SQL Builders are typically not used directly by application business logic, but rather to be wrapped in some Application Data Access Layer (e.g., DAOs or MACs - Model Access Controller -). In fact, even when using ORMs, it is often a good code design to wrap those access via some data access layers.
Goals for first 0.1.x releases:
- sqlx - Will probably be SQLX centric.
- PostgreSQL - Will probably support SQLX only. Contributions for another database (via sqlx) welcome
- Macros - to keep thing DRY (but they are optional, all can be implemented via trait objects)
Early API Example (just conceptual for now)
// Optional: to be able to use the sqlx_exec::fetch_as...
// implements sqlb::HasFields for dynamic binding
let patch_data = TodoPatch ;
// INSERT - Insert a new Todo from a Partial todo
let sb = insert.table.data;
let sb = sb.returning;
let = sb..await?;
// SELECT - Get all todos
let sb = select.table.columns.order_by;
let todos: = sb.fetch_as_all.await?;
assert_eq!;
Latest Breaking Changes
0.0.7
-sqlb::insert().table("todo")
(in 0.0.7) rather thansqlb::insert("toto")
(<=0.0.6) (for all SqlBuilders)
For sqlb Dev
Start a PostgreSQL
# In terminal 1 - start postges
# In terminal 2 - (optional) launch psql on the Postgres instance above
# In terminal 3 - MUST run with `--test-threads=1` to avoid database access conflicts
# or watch a particular test target