Expand description
SQLite driver for SQLModel Rust.
sqlmodel-sqlite is the SQLite driver for the SQLModel ecosystem. It implements
the Connection trait from sqlmodel-core, providing a lightweight backend that is
ideal for local development, embedded use, and testing.
§Role In The Architecture
- Implements
sqlmodel-core::Connectionfor SQLite - Supplies FFI-backed execution and type conversion
- Enables
sqlmodel-queryandsqlmodel-sessionto run against SQLite
This crate provides a SQLite database driver using FFI bindings to libsqlite3.
It implements the Connection trait from sqlmodel-core for seamless integration
with the rest of the SQLModel ecosystem.
§Features
- Full Connection trait implementation
- Transaction support with savepoints
- Type-safe parameter binding
- In-memory and file-based databases
- Configurable open flags and busy timeout
§Example
ⓘ
use sqlmodel_sqlite::{SqliteConnection, SqliteConfig};
use sqlmodel_core::{Connection, Value, Cx, Outcome};
// Open an in-memory database
let conn = SqliteConnection::open_memory().unwrap();
// Create a table
conn.execute_raw("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)").unwrap();
// Insert data using the Connection trait
let cx = Cx::for_testing();
match conn.insert(&cx, "INSERT INTO users (name) VALUES (?)", &[Value::Text("Alice".into())]).await {
Outcome::Ok(id) => println!("Inserted user with id: {}", id),
Outcome::Err(e) => eprintln!("Error: {}", e),
_ => {}
}§Type Mapping
| Rust Type | SQLite Type |
|---|---|
bool | INTEGER (0/1) |
i8, i16, i32 | INTEGER |
i64 | INTEGER |
f32, f64 | REAL |
String | TEXT |
Vec<u8> | BLOB |
Option<T> | NULL or T |
Date, Time, Timestamp | TEXT (ISO-8601) |
Uuid | BLOB (16 bytes) |
Json | TEXT |
§Thread Safety
SqliteConnection is both Send and Sync, using internal mutex
synchronization to protect the underlying SQLite handle. This allows
connections to be shared across async tasks safely.
Re-exports§
pub use connection::OpenFlags;pub use connection::SqliteConfig;pub use connection::SqliteConnection;pub use connection::SqliteTransaction;
Modules§
- connection
- SQLite connection implementation.
- ffi
- Low-level FFI bindings to libsqlite3.
- types
- Type encoding and decoding between Rust and SQLite.
Functions§
- sqlite_
version - Re-export the SQLite library version.
- sqlite_
version_ number - Re-export the SQLite library version number.