1

Install

Add the Turso crate to your Rust project:
cargo add turso
2

Connect

Here’s how you can connect to a local SQLite database:
use turso::Builder;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let db = Builder::new_local("sqlite.db").build().await?;
    let conn = db.connect()?;

    Ok(())
}
3

Create table

Create a table for users:
conn.execute(
    "CREATE TABLE IF NOT EXISTS users (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        username TEXT NOT NULL
    )",
    ()
).await?;
4

Insert data

Insert some data into the users table:
conn.execute("INSERT INTO users (username) VALUES (?)", ("alice",)).await?;
conn.execute("INSERT INTO users (username) VALUES (?)", ("bob",)).await?;
5

Query data

Query all users from the table:
let res = conn.query("SELECT * FROM users", ()).await?;
println!("{:?}", res);