bsql — Safe SQL for Rust
If it compiles, the SQL is correct.
bsql validates every SQL query against a real database at compile time.
There is no query() function. There is no escape hatch. There is query!
— validated, typed, checked. If the binary is produced, every SQL query in
it is correct.
Quick Start
[]
= "0.16"
= { = "1", = ["rt-multi-thread", "macros"] }
Set the database URL for compile-time validation:
Then:
use ;
async
Three methods — that's it
| Method | Returns | Use |
|---|---|---|
.fetch(&pool) |
Vec<Row> |
SELECT queries |
.run(&pool) |
u64 |
INSERT, UPDATE, DELETE |
.defer(&tx) |
() |
Buffer in transaction |
Power users: fetch_one, fetch_optional, fetch_stream, for_each also available.
No escape hatch
There is no bsql::query() function. There is no raw_sql(). There is no
way to execute unchecked SQL through bsql. If you need unchecked SQL, use
tokio-postgres directly. bsql will not become the thing it replaces.