Skip to main content
Builder is the entry point for opening a Turso database in Rust. Configure it with optional feature flags and call .build().await to get a Database.
use turso::Builder;

let db = Builder::new_local("app.db").build().await?;

Builder::new_local(path)

Creates a Builder that will open the SQLite database at path. If the file does not exist it will be created.
use turso::Builder;

// File-backed database
let builder = Builder::new_local("app.db");

// In-memory database
let builder = Builder::new_local(":memory:");
path
&str
required
Path to the database file, or ":memory:" for an in-memory database.
Returns Builder

builder.build().await

Opens the database and returns a Database. This is async because Turso may need to perform I/O during database initialization (for example, reading WAL frames).
let db = Builder::new_local("app.db").build().await?;
Returns Result<Database>

Optional configuration methods

All configuration methods take self and return Self, so they can be chained:
let db = Builder::new_local("app.db")
    .experimental_attach(true)
    .experimental_custom_types(true)
    .build()
    .await?;

.experimental_encryption(enabled)

Enables the experimental at-rest encryption feature.
enabled
bool
required
Pass true to enable encryption.
Returns Builder

.with_encryption(opts)

Provides an EncryptionOpts value containing the cipher name and hex-encoded key. Implicitly enables encryption.
use turso::{Builder, EncryptionOpts};

let opts = EncryptionOpts {
    cipher: "aegis256".to_string(),
    hexkey: "2d7a30108d3eb3e4...".to_string(),
};
let db = Builder::new_local("app.db")
    .with_encryption(opts)
    .build()
    .await?;
opts
EncryptionOpts
required
Encryption configuration.
Returns Builder

.experimental_attach(enabled)

Enables the ATTACH DATABASE SQL command. Returns Builder

.experimental_custom_types(enabled)

Enables custom column type handling. Returns Builder

.experimental_index_method(enabled)

Enables user-defined index methods. Returns Builder

.experimental_materialized_views(enabled)

Enables experimental materialized view support. Returns Builder

.with_io(vfs)

Overrides the I/O backend. Supported values depend on the target platform.
vfs
String
required
VFS identifier string.
Returns Builder

The Database type

After calling .build() you hold a Database. It is Clone and cheap to share across tasks — internally it is an Arc.
// Database is Clone
let db2 = db.clone();
let conn = db2.connect()?;
See Connection for the methods available after calling db.connect().

Build docs developers (and LLMs) love