Crate async_rusqlite

Source
Expand description

§Async-rusqlite

A tiny async wrapper around rusqlite. Use crate::Connection to open a connection, and then crate::Connection::call() to execute commands against it.

use async_rusqlite::Connection;

#[derive(Debug)]
struct Person {
    id: i32,
    name: String,
    data: Option<Vec<u8>>,
}

let conn = Connection::open_in_memory().await?;

conn.call(|conn| {
    conn.execute(
        "CREATE TABLE person (
            id   INTEGER PRIMARY KEY,
            name TEXT NOT NULL,
            data BLOB
        )",
        (),
    )
}).await?;

let me = Person {
    id: 0,
    name: "Steven".to_string(),
    data: None,
};

conn.call(move |conn| {
    conn.execute(
        "INSERT INTO person (name, data) VALUES (?1, ?2)",
        (&me.name, &me.data),
    )
}).await?;

Re-exports§

pub use rusqlite;

Structs§

AlreadyClosed
If the connection is already closed, this will be returned for the user to convert into their own error type. This can be converted into Error and rusqlite::Error so that either can be returned in the Connection::call() function.
Connection
A handle which allows access to the underlying rusqlite::Connection via Connection::call().
ConnectionBuilder

Enums§

Error
An error emitted if closing the connection fails.