#database #sqlite #test


Creates temporary SQLite database for testing using diesel

4 releases

0.1.3 May 10, 2020
0.1.2 May 8, 2020
0.1.1 May 8, 2020
0.1.0 May 7, 2020

#200 in Testing

41 downloads per month

MIT license

56 lines


Build Status Documentation crates.io

Creates temporary SQLite database for testing using diesel.

nafta = "0.1"

Minimal example

// Creates empty SQLite database in temporary folder
let test_db = nafta::sqlite::TestDb::new();

// Work with the connetion
let conn = test_db.conn();

// You can check that database file was really removed
let path = test_db.db_path.clone();
// Necessary to drop anything which can block file
// Dropping `test_db` to check it was really removed

Example with migration

// Database
extern crate diesel;

extern crate diesel_migrations;

// This macro from `diesel_migrations` defines an `embedded_migrations` module
// containing a function named `run`. This allows the example to be run and
// tested without any outside setup of the database.

mod tests {

    async fn test_get_user() {
        let test_db = nafta::sqlite::TestDb::new();
        let conn = test_db
            .expect("Not possible to get pooled connection");

        // Database migration
        embedded_migrations::run(&conn).expect("Migration not possible to run");

        // Example method to get all users
        let all_user = db::users::get_all_users(test_db.pool);

Building on windows

See build batch for windows: .github/install-sqlite.bat


~410K SLoC