mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-19 21:55:03 +01:00
Drop the in-memory database (#613)
* Drop the in-memory database Fixes #607 This PR drops the implementation of in-memory database traits. They are useful for testing purposes since the tests should test our codebase and assume the database works as expected (although a follow-up PR should write a sanity test suite for all database trait implementors). As complexity is worth with database requirements to simplify complexity and add more robustness, for instance, with the following plans to add support for transactions or buffered writes, it would become more complex and time-consuming to support a correct database trait. This PR drops the implementation and replaces it with a SQLite memory instance * Remove OnceCell<Mint> Without this change, a single Mint is shared for all tests, and the first tests to run and shutdown makes the other databases (not-reachable, as dropping the tokio engine would also drop the database instance). There is no real reason, other than perhaps performance. The mint should perhaps run in their own tokio engine and share channels as API interfaces, or a new instance should be created in each tests * Fixed bug with foreign keys [1] https://gist.github.com/crodas/bad00997c63bd5ac58db3c5bd90747ed * Show more debug on failure * Remove old code * Remove old references to WalletMemoryDatabase
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use bitcoin::bip32::DerivationPath;
|
||||
@@ -20,35 +19,28 @@ use cdk_common::{
|
||||
};
|
||||
use error::Error;
|
||||
use lightning_invoice::Bolt11Invoice;
|
||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqlitePoolOptions, SqliteRow};
|
||||
use sqlx::Row;
|
||||
use sqlx::sqlite::SqliteRow;
|
||||
use sqlx::{Pool, Row, Sqlite};
|
||||
use uuid::fmt::Hyphenated;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::common::create_sqlite_pool;
|
||||
|
||||
pub mod error;
|
||||
pub mod memory;
|
||||
|
||||
/// Mint SQLite Database
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MintSqliteDatabase {
|
||||
pool: SqlitePool,
|
||||
pool: Pool<Sqlite>,
|
||||
}
|
||||
|
||||
impl MintSqliteDatabase {
|
||||
/// Create new [`MintSqliteDatabase`]
|
||||
pub async fn new(path: &Path) -> Result<Self, Error> {
|
||||
let path = path.to_str().ok_or(Error::InvalidDbPath)?;
|
||||
let db_options = SqliteConnectOptions::from_str(path)?
|
||||
.busy_timeout(Duration::from_secs(5))
|
||||
.read_only(false)
|
||||
.create_if_missing(true)
|
||||
.auto_vacuum(sqlx::sqlite::SqliteAutoVacuum::Full);
|
||||
|
||||
let pool = SqlitePoolOptions::new()
|
||||
.max_connections(1)
|
||||
.connect_with(db_options)
|
||||
.await?;
|
||||
|
||||
Ok(Self { pool })
|
||||
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?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Migrate [`MintSqliteDatabase`]
|
||||
|
||||
Reference in New Issue
Block a user