8 releases (5 breaking)
0.5.1 | Nov 27, 2023 |
---|---|
0.5.0 | Nov 26, 2023 |
0.4.0 | Aug 31, 2023 |
0.3.0 | May 28, 2023 |
0.0.1 | Apr 23, 2023 |
#2471 in Database interfaces
40 downloads per month
25KB
443 lines
Sqliter
A small, opinionated wrapper around Rusqlite which handles migrations for you, and exposes a small around of configuration around instantiating Sqlite connections.
lib.rs
:
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?;
Dependencies
~23MB
~431K SLoC