mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-23 14:55:48 +01:00
feat: Add support for sqlcipher
This commit is contained in:
@@ -12,7 +12,10 @@ use super::MintSqliteDatabase;
|
||||
|
||||
/// Creates a new in-memory [`MintSqliteDatabase`] instance
|
||||
pub async fn empty() -> Result<MintSqliteDatabase, database::Error> {
|
||||
#[cfg(not(feature = "sqlcipher"))]
|
||||
let db = MintSqliteDatabase::new(":memory:").await?;
|
||||
#[cfg(feature = "sqlcipher")]
|
||||
let db = MintSqliteDatabase::new(":memory:", "memory".to_string()).await?;
|
||||
db.migrate().await;
|
||||
Ok(db)
|
||||
}
|
||||
|
||||
@@ -68,12 +68,25 @@ impl MintSqliteDatabase {
|
||||
}
|
||||
|
||||
/// Create new [`MintSqliteDatabase`]
|
||||
#[cfg(not(feature = "sqlcipher"))]
|
||||
pub async fn new<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
|
||||
Ok(Self {
|
||||
pool: create_sqlite_pool(path.as_ref().to_str().ok_or(Error::InvalidDbPath)?).await?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Create new [`MintSqliteDatabase`]
|
||||
#[cfg(feature = "sqlcipher")]
|
||||
pub async fn new<P: AsRef<Path>>(path: P, password: String) -> Result<Self, Error> {
|
||||
Ok(Self {
|
||||
pool: create_sqlite_pool(
|
||||
path.as_ref().to_str().ok_or(Error::InvalidDbPath)?,
|
||||
password,
|
||||
)
|
||||
.await?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Migrate [`MintSqliteDatabase`]
|
||||
pub async fn migrate(&self) {
|
||||
sqlx::migrate!("./src/mint/migrations")
|
||||
|
||||
Reference in New Issue
Block a user