https://github.com/ryanfowler/async-sqlite
A Rust library to interact with sqlite from an async context.
https://github.com/ryanfowler/async-sqlite
async rusqlite rust sqlite sqlite3
Last synced: 25 days ago
JSON representation
A Rust library to interact with sqlite from an async context.
- Host: GitHub
- URL: https://github.com/ryanfowler/async-sqlite
- Owner: ryanfowler
- License: mit
- Created: 2023-06-25T14:35:53.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2026-03-16T15:03:34.000Z (about 2 months ago)
- Last Synced: 2026-03-17T01:30:00.147Z (about 2 months ago)
- Topics: async, rusqlite, rust, sqlite, sqlite3
- Language: Rust
- Homepage:
- Size: 93.8 KB
- Stars: 23
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
- Agents: AGENTS.md
Awesome Lists containing this project
README
# async-sqlite
[](https://crates.io/crates/async-sqlite)
[](https://docs.rs/async-sqlite)
A library to interact with sqlite from an async context.
This library is tested on both [tokio](https://docs.rs/tokio/latest/tokio/)
and [smol](https://docs.rs/smol/latest/smol/), however
it should be compatible with all async runtimes.
## Install
Add `async-sqlite` to your "dependencies" in your Cargo.toml file.
This can be done by running the command:
```
cargo add async-sqlite
```
## Usage
A `Client` represents a single background sqlite3 connection that can be called
concurrently from any thread in your program.
To create a sqlite client and run a query:
```rust
use async_sqlite::{ClientBuilder, JournalMode};
let client = ClientBuilder::new()
.path("/path/to/db.sqlite3")
.journal_mode(JournalMode::Wal)
.open()
.await?;
let value: String = client.conn(|conn| {
conn.query_row("SELECT val FROM testing WHERE id=?", [1], |row| row.get(0))
}).await?;
println!("Value is: {value}");
```
A `Pool` represents a collection of background sqlite3 connections that can be
called concurrently from any thread in your program.
To create a sqlite pool and run a query:
```rust
use async_sqlite::{JournalMode, PoolBuilder};
let pool = PoolBuilder::new()
.path("/path/to/db.sqlite3")
.journal_mode(JournalMode::Wal)
.open()
.await?;
let value: String = pool.conn(|conn| {
conn.query_row("SELECT val FROM testing WHERE id=?", [1], |row| row.get(0))
}).await?;
println!("Value is: {value}");
```
## Cargo Features
This library tries to export almost all features that the underlying
[rusqlite](https://docs.rs/rusqlite/latest/rusqlite/) library contains.
A notable difference is that the `bundled` feature is **enabled** by default,
but can be disabled with the following line in your Cargo.toml:
```toml
async-sqlite = { version = "*", default-features = false }
```