sqlb-0.0.2 has been yanked.
IMPORTANT - Still experimental and extremely incomplete. All 0.0.x version will be experimental and probably break APIs in each release
sqlb is intended to be a simple and progressive SQLBuilder for Rust, independent from database SQL executor.
- Simple - Focused on providing an expressive, composable, and typed way to build parameterized SQL statements. The goal is NOT to abstract SQL but to make it expressive, composable, and typed pragmatically.
- Progressive - From arbitrary data in and out (list of names/values), to eventually, struct and mapping rules.
- Focused - Not an ORM, Not a database "executor/driver." Executor wrappers will be provided as features. The first wrapper will be for sqlx, and eventually one for tokio-postgres. But since the core
sqlb
api is about creating a parameterized sql (builder.sql() -> String
) and a list of values (builder.vals() -> Vec<val>
), integrating with any other database connectivity libraries should be trivial.
NOTE: SQL Builders are typically not to be used directly by application business logic, but rather to be wrapped in some sort of Application Data Access Layer (DAOs, DM, patterns).
Scope for first 0.1.x releases:
- Support for the PostgreSQL dialect. If more public interest, a dialect API will be evaluated.
- No macros, so
Get_Fields
needs to be written by hand. As the APIs/Models mature, macros will be implemented to avoid boilerplate code. - Currently, the Value system
Val
is extremely rudimentary, and more thought is needed to find the right model there. Feedback welcome.
Early API Example (just conceptual for now)
Insert:
let sb = insert.data;
let sb = sb.returning;
let = .await?;
Select:
let sb = select.columns.order_by;
let todos: = fetch_as_all.await?;
assert_eq!;
The data setup:
// Optional: to be able to use the sqlx_exec::fetch_as...
For sqlb Dev
Start a postgressql
# In terminal 1 - start postges
# In terminal 2 - (optional) launch psql on the postges instance above
# In terminal 3 - MUST run with `--test-threads=1` to avoid database access conflicts
# or watch a particular test target