#sqlite #tokio #async #sql

tokio-sqlite

Asynchronous SQLite client

5 releases

0.1.4 Mar 22, 2024
0.1.3 Feb 7, 2024
0.1.2 Jan 25, 2024
0.1.1 Jan 24, 2024
0.1.0 Jan 24, 2024

#1549 in Database interfaces

Download history 12/week @ 2024-01-19 1/week @ 2024-01-26 4/week @ 2024-02-02 18/week @ 2024-02-23 8/week @ 2024-03-01 15/week @ 2024-03-08 4/week @ 2024-03-15 123/week @ 2024-03-22 25/week @ 2024-03-29 1/week @ 2024-04-05

160 downloads per month

MIT/Apache

20KB
509 lines

tokio-sqlite

crates.io codecov

Usage

use tokio_sqlite::{Connection, Value};

struct Post {
    id: i32,
    title: String,
    author: Option<i64>,
}

#[tokio::main]
async fn main() {
    let mut conn = Connection::open(":memory:").await.unwrap();
    conn.execute(
        "CREATE TABLE post (
            id     INTEGER PRIMARY KEY,
            title  TEXT NOT NULL,
            author BIGINT
        )",
        [],
    )
    .await
    .unwrap();
    let post = Post {
        id: 1,
        title: "tokio-sqlite".into(),
        author: None,
    };
    let mut rows = conn
        .query(
            "INSERT INTO post (title, author) VALUES ($1, $2) RETURNING id",
            [post.title.into(), post.author.into()],
        )
        .await
        .unwrap();
    let row = rows.next().await.unwrap().unwrap();
    assert_eq!(row.values()[0], Value::Integer(post.id.into()));
}

License

tokio-sqlite is distributed under the terms of both the MIT license and the Apache 2.0 License.

Dependencies

~25MB
~456K SLoC