1use cdk_sql_common::mint::SQLMintAuthDatabase;
4use cdk_sql_common::SQLMintDatabase;
5
6use crate::common::SqliteConnectionManager;
7
8pub mod memory;
9
10pub type MintSqliteDatabase = SQLMintDatabase<SqliteConnectionManager>;
12
13#[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 bug_opening_relative_path() {
36 let config: Config = "test.db".into();
37
38 let pool = Pool::<SqliteConnectionManager>::new(config);
39 let db = pool.get();
40 assert!(db.is_ok());
41 let _ = remove_file("test.db");
42 }
43
44 #[tokio::test]
45 async fn open_legacy_and_migrate() {
46 let file = format!(
47 "{}/db.sqlite",
48 std::env::temp_dir().to_str().unwrap_or_default()
49 );
50
51 {
52 let _ = remove_file(&file);
53 #[cfg(not(feature = "sqlcipher"))]
54 let config: Config = file.as_str().into();
55 #[cfg(feature = "sqlcipher")]
56 let config: Config = (file.as_str(), "test").into();
57
58 let pool = Pool::<SqliteConnectionManager>::new(config);
59
60 let conn = pool.get().expect("valid connection");
61
62 query(include_str!("../../tests/legacy-sqlx.sql"))
63 .expect("query")
64 .execute(&*conn)
65 .await
66 .expect("create former db failed");
67 }
68
69 #[cfg(not(feature = "sqlcipher"))]
70 let conn = MintSqliteDatabase::new(file.as_str()).await;
71
72 #[cfg(feature = "sqlcipher")]
73 let conn = MintSqliteDatabase::new((file.as_str(), "test")).await;
74
75 assert!(conn.is_ok(), "Failed with {:?}", conn.unwrap_err());
76
77 let _ = remove_file(&file);
78 }
79}