Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -805,13 +805,7 @@ dictionary Condition {
// bdk_sqlite crate
// ------------------------------------------------------------------------

interface Connection {
[Throws=SqliteError]
constructor(string path);

[Name=new_in_memory, Throws=SqliteError]
constructor();
};
typedef interface Connection;

// ------------------------------------------------------------------------
// bdk crate - descriptor module
Expand Down
10 changes: 10 additions & 0 deletions bdk-ffi/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@ use bdk_wallet::rusqlite::Connection as BdkConnection;
use std::sync::Mutex;
use std::sync::MutexGuard;

/// A connection to a SQLite database.
#[derive(uniffi::Object)]
pub struct Connection(Mutex<BdkConnection>);

#[uniffi::export]
impl Connection {
/// Open a new connection to a SQLite database. If a database does not exist at the path, one is
/// created.
#[uniffi::constructor]
pub fn new(path: String) -> Result<Self, SqliteError> {
let connection = BdkConnection::open(path)?;
Ok(Self(Mutex::new(connection)))
}

/// Open a new connection to an in-memory SQLite database.
#[uniffi::constructor]
pub fn new_in_memory() -> Result<Self, SqliteError> {
let connection = BdkConnection::open_in_memory()?;
Ok(Self(Mutex::new(connection)))
}
}

impl Connection {
pub(crate) fn get_store(&self) -> MutexGuard<BdkConnection> {
self.0.lock().expect("must lock")
}
Expand Down
Loading