tokio-sqlite

Crates.iotokio-sqlite
lib.rstokio-sqlite
version0.1.5
sourcesrc
created_at2024-01-24 15:23:05.388783
updated_at2024-08-27 23:52:37.471374
descriptionAsynchronous SQLite client
homepage
repositoryhttps://github.com/udovin/tokio-sqlite
max_upload_size
id1112440
size44,944
Ivan Udovin (udovin)

documentation

README

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.

Commit count: 7

cargo fmt