Expand description
§Drizzle for Rust
Drizzle is a type-safe SQL query builder for Rust, supporting multiple database drivers including SQLite (via rusqlite, libsql, turso) and PostgreSQL (via sqlx).
§Quick Start
use drizzle::prelude::*;
use drizzle::rusqlite::Drizzle;
#[SQLiteTable(name = "Users")]
struct User {
#[integer(primary)]
id: i32,
#[text]
name: String,
#[text]
email: Option<String>,
}
#[derive(SQLiteSchema)]
struct Schema {
user: User,
}
// Connect to database and perform operations
let conn = rusqlite::Connection::open_in_memory()?;
let (db, Schema { user, .. }) = Drizzle::new(conn, Schema::new());
// Create tables
db.create()?;
// Insert data
db.insert(user)
.values([InsertUser::new("John Doe").with_email("john@example.com")])
.execute()?;
// Query data
let users: Vec<SelectUser> = db.select(()).from(user).all()?;
assert_eq!(users.len(), 1);
assert_eq!(users[0].id, 1);
assert_eq!(users[0].name, "John Doe");
assert_eq!(users[0].email, Some("john@example.com".to_string()));§Database Support
| Database | Driver | Feature Flag | Status |
|---|---|---|---|
| SQLite | rusqlite | rusqlite | ✅ |
| SQLite | libsql | libsql | ✅ |
| SQLite | turso | turso | ✅ |
| PostgreSQL | sqlx | sqlx-postgres | 🚧 |
| MySQL | sqlx | mysql | 🚧 |
Modules§
- core
- Core functionality shared across all database implementations.
- error
- Error types and result handling.
- prelude
- A comprehensive prelude that brings commonly used items into scope.
Macros§
- sql
- A procedural macro for building SQL queries with embedded expressions.
Type Aliases§
- Result
- Result type for database operations