2 unstable releases
Uses new Rust 2024
| new 0.2.0 | Feb 15, 2026 |
|---|---|
| 0.1.1 | Feb 5, 2026 |
#1768 in Database interfaces
6,818 downloads per month
Used in sqlmodel
600KB
13K
SLoC
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.
sqlmodel-sqlite
SQLite driver implementing the SQLModel Connection trait.
Role in the SQLModel Rust System
- FFI-backed SQLite execution and type conversion.
- Lightweight backend for local/dev/test usage.
- Used by sqlmodel-query and sqlmodel-session at runtime.
Usage
Most users should depend on sqlmodel and import from sqlmodel::prelude::*.
Use this crate directly if you are extending internals or building tooling around the core APIs.
Links
Dependencies
~27–44MB
~676K SLoC