qraft
qraft is a lightweight SQL query builder for Rust. It provides a fluent API
for assembling select, insert, update and delete statements and
supports parameter binding out of the box. When the optional sqlx features
are enabled, queries can be executed directly against a database.
Features
-
Compose complex queries using a builder style API
-
Support for PostgreSQL, MySQL and SQLite dialects
-
Integration with
sqlxfor executing queries -
Helper functions to embed raw SQL fragments or sub‑queries
-
Optional features for
time,chrono,uuidandserde_jsonbindings
Installation
Add qraft to your Cargo.toml and enable the dialect features you need:
[]
= { = "0.1.0", = ["postgres", "chrono"] }
Example
use ;
let mut query = table;
query.select.where_eq;
let sql = query.;
assert_eq!;
Joins
use ;
let mut query = table;
query
.join
.join
.select;
let sql = query.;
assert_eq!;
Aggregates
let mut query = table;
query.where_eq.select_avg;
let sql = query.;
assert_eq!;
Inserts
let mut builder = table;
let insert_sql = builder
.inserting
.values_with
.;
assert_eq!;
Exists Subquery
let mut query = new;
query.select_exists;
let sql = query.;
assert_eq!;
License
This project is released under the MIT License.