2 unstable releases

new 0.2.3 Mar 17, 2025
0.1.1 May 31, 2024
0.1.0 May 31, 2024

#1392 in Database interfaces

Download history 1/week @ 2024-12-04 2/week @ 2024-12-11 93/week @ 2025-03-12

93 downloads per month

MIT license

11KB
163 lines

spin-sqlite-connection

Motivation

I wrote this crate because i wanted to test sqlite database operations in a Fermyon spin application.

This crate uses conditional compilation. The spin-sdk crate is used for database operation if target-family = "wasm", else the rusqlite crate is used. Then rusqlite connection uses a in-memory database which is used in testing.

Example

    const MIGRATIONS: &str = "CREATE TABLE IF NOT EXISTS user (id TEXT PRIMARY KEY, name TEXT NOT NULL, password TEXT NOT NULL);"
    const INSERT: &str = "INSERT INTO user (id, name, password) VALUES ('LKtQNwbBsQd9aXgMbmptKP', 'paul', 'password');";

    let connection = DbConnection::<Box<dyn std::error::Error>>::try_open_default(Some(MIGRATIONS)).unwrap();
    let count = connection.execute(INSERT, &[]).unwrap();
    assert_eq!(count, 1);

Dependencies

~4–8MB
~158K SLoC