9 releases (5 breaking)

0.5.0 Feb 7, 2025
0.4.0 Jan 14, 2025
0.3.1 Jul 23, 2024
0.2.2 Feb 9, 2024
0.0.1 Jun 25, 2023

#268 in Database interfaces

Download history 361/week @ 2024-10-27 504/week @ 2024-11-03 367/week @ 2024-11-10 739/week @ 2024-11-17 219/week @ 2024-11-24 321/week @ 2024-12-01 512/week @ 2024-12-08 462/week @ 2024-12-15 424/week @ 2024-12-22 908/week @ 2024-12-29 828/week @ 2025-01-05 879/week @ 2025-01-12 684/week @ 2025-01-19 768/week @ 2025-01-26 1368/week @ 2025-02-02 1110/week @ 2025-02-09

4,060 downloads per month
Used in 3 crates (2 directly)

MIT license

30KB
460 lines

async-sqlite

A library to interact with sqlite from an async context.

This library is tested on both tokio and async_std, 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:

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:

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 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:

async-sqlite = { version = "*", default-features = false }

Dependencies

~29MB
~476K SLoC