# Connect to Turso using Rust

> Connect to Turso using Rust — Turso documentation.
> Canonical HTML: https://tursodb.cn/docs/connect/rust/
> Upstream Source (MIT): https://docs.turso.tech/connect/rust
> Language: en

---
**1. Install**

Add the Turso crate to your Rust project:

```bash
cargo add turso
```

**2. Connect**

Here's how you can connect to a local SQLite database:

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

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

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

```rust
let res = conn.query("SELECT * FROM users", ()).await?;
println!("{:?}", res);
```
