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