Skip to main content
The turso crate provides an async Rust API for embedding Turso in your application.

Installation

Add the dependency to Cargo.toml:
[dependencies]
turso = "*"
tokio = { version = "1", features = ["full"] }

Async runtime

All turso APIs are async. The crate is runtime-agnostic but is tested primarily with Tokio. Any async executor that supports Future + Send should work.

Quick start

use turso::Builder;

#[tokio::main]
async fn main() -> turso::Result<()> {
    // Build a database from a local file (or ":memory:")
    let db = Builder::new_local(":memory:").build().await?;

    // Open a connection
    let conn = db.connect()?;

    // Execute DDL
    conn.execute(
        "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, email TEXT)",
        (),
    )
    .await?;

    // Insert a row
    conn.execute(
        "INSERT INTO users (email) VALUES (?)",
        ["[email protected]"],
    )
    .await?;

    // Query rows
    let mut rows = conn.query("SELECT id, email FROM users", ()).await?;
    while let Some(row) = rows.next().await? {
        let id: i64 = row.get(0)?;
        let email: String = row.get(1)?;
        println!("{id}: {email}");
    }

    Ok(())
}

API flow

Builder::new_local(path)
  └─ .build().await  →  Database
       └─ .connect()    →  Connection
            ├─ .query(...)  →  Rows
            ├─ .execute(...)  →  u64 (rows affected)
            └─ .prepare(...)  →  Statement

Optional builder features

The Builder exposes feature flags for experimental capabilities:
MethodDescription
.experimental_encryption(bool)Enable at-rest encryption
.with_encryption(EncryptionOpts)Supply encryption key and cipher
.experimental_attach(bool)Enable ATTACH DATABASE
.experimental_custom_types(bool)Enable custom column types
.experimental_index_method(bool)Enable custom index methods
.experimental_materialized_views(bool)Enable materialized views
.with_io(vfs)Override the I/O backend

Exports

ItemKindDescription
BuilderstructConstructs a Database
DatabasestructPoints to a database file
ConnectionstructAn open connection
StatementstructA compiled statement
RowsstructQuery result set
RowstructA single result row
ValueenumSQL value (Null, Integer, Real, Text, Blob)
ErrorenumAll error variants
Result<T>type aliasstd::result::Result<T, Error>
IntoParamstraitConvert Rust values into bind parameters

Pages in this section

Builder

Construct a Database from a path or memory.

Connection

Execute queries and manage transactions.

Statement

Compiled statement, row iteration, and column access.

Build docs developers (and LLMs) love