Crate sqliter

Source
Expand description

§Sqliter

Make light work of connecting and migrating an SQLite database.

Built on async_rusqlite; a thin async wrapper around rusqlite that is runtime agnostic.

use sqliter::{ Connection, ConnectionBuilder, ConnectionBuilderError };

async fn open_connection() -> Result<Connection, ConnectionBuilderError> {
    // This must never change for a given app; the database won't open if
    // the app_id does not equal the one we have set here.
    const APP_ID: i32 = 1337;

    ConnectionBuilder::new()
        .app_id(APP_ID)
        // Migrations should never change; this list will simply grow over time
        // To accomodate the updates needed as the app matures.
        .add_migration(1, |conn| {
            conn.execute("CREATE TABLE user ( id INTEGER PRIMARY KEY )", ())
                .map(|_| ())
        })
        .add_migration(2, |conn| {
            conn.execute("ALTER TABLE user ADD COLUMN name TEXT NOT NULL DEFAULT 'Unknown'", ())
                .map(|_| ())
        })
        .open_in_memory()
        .await
}

let conn = open_connection().await?;

conn.call(|conn| {
    conn.execute("INSERT INTO user (name) VALUES ('James')", ())
}).await?;

Re-exports§

pub use async_rusqlite;
pub use async_rusqlite::rusqlite;

Structs§

Connection
A handle which allows access to the underlying rusqlite::Connection via Connection::call().
ConnectionBuilder
An opinionated connection builder which ultimately hands back an async_rusqlite::Connection after checking the app ID and performing any necessary migrations.
Migrations
Define a set of migrations to apply to an SQLite connection.

Enums§

ConnectionBuilderError