cdk_sqlite/mint/
mod.rs

1//! SQLite Mint
2
3use cdk_sql_common::mint::SQLMintAuthDatabase;
4use cdk_sql_common::SQLMintDatabase;
5
6use crate::common::SqliteConnectionManager;
7
8pub mod memory;
9
10/// Mint SQLite implementation with rusqlite
11pub type MintSqliteDatabase = SQLMintDatabase<SqliteConnectionManager>;
12
13/// Mint Auth database with rusqlite
14#[cfg(feature = "auth")]
15pub type MintSqliteAuthDatabase = SQLMintAuthDatabase<SqliteConnectionManager>;
16
17#[cfg(test)]
18mod test {
19    use std::fs::remove_file;
20
21    use cdk_common::mint_db_test;
22    use cdk_sql_common::pool::Pool;
23    use cdk_sql_common::stmt::query;
24
25    use super::*;
26    use crate::common::Config;
27
28    async fn provide_db(_test_name: String) -> MintSqliteDatabase {
29        memory::empty().await.unwrap()
30    }
31
32    mint_db_test!(provide_db);
33
34    #[tokio::test]
35    async fn open_legacy_and_migrate() {
36        let file = format!(
37            "{}/db.sqlite",
38            std::env::temp_dir().to_str().unwrap_or_default()
39        );
40
41        {
42            let _ = remove_file(&file);
43            #[cfg(not(feature = "sqlcipher"))]
44            let config: Config = file.as_str().into();
45            #[cfg(feature = "sqlcipher")]
46            let config: Config = (file.as_str(), "test").into();
47
48            let pool = Pool::<SqliteConnectionManager>::new(config);
49
50            let conn = pool.get().expect("valid connection");
51
52            query(include_str!("../../tests/legacy-sqlx.sql"))
53                .expect("query")
54                .execute(&*conn)
55                .await
56                .expect("create former db failed");
57        }
58
59        #[cfg(not(feature = "sqlcipher"))]
60        let conn = MintSqliteDatabase::new(file.as_str()).await;
61
62        #[cfg(feature = "sqlcipher")]
63        let conn = MintSqliteDatabase::new((file.as_str(), "test")).await;
64
65        assert!(conn.is_ok(), "Failed with {:?}", conn.unwrap_err());
66
67        let _ = remove_file(&file);
68    }
69}