Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] added sqlx, removed rusqlite #1552

Closed
Show file tree
Hide file tree
Changes from 1 commit
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: 6 additions & 2 deletions crates/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ hashbrown = { version = "0.9.1", optional = true, features = ["serde"] }
miniscript = { version = "12.0.0", optional = true, default-features = false }

# Feature dependencies
rusqlite = { version = "0.31.0", features = ["bundled"], optional = true }
#rusqlite = { version = "0.31.0", features = ["bundled"], optional = true }
sqlx = { version = "0.7.4", features = ["migrate", "runtime-tokio-rustls", "postgres", "json", "chrono", "uuid"] , optional = true}
async-trait = "0.1.81"

serde_json = {version = "1", optional = true }

[dev-dependencies]
Expand All @@ -32,4 +35,5 @@ proptest = "1.2.0"
default = ["std", "miniscript"]
std = ["bitcoin/std", "miniscript?/std"]
serde = ["dep:serde", "bitcoin/serde", "miniscript?/serde"]
rusqlite = ["std", "dep:rusqlite", "serde", "serde_json"]
#rusqlite = ["std", "dep:rusqlite", "serde", "serde_json"]
sqlx = ["std", "dep:sqlx", "serde", "serde_json"]
8 changes: 4 additions & 4 deletions crates/chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ mod spk_iter;
pub use indexer::keychain_txout;
#[cfg(feature = "miniscript")]
pub use spk_iter::*;
#[cfg(feature = "rusqlite")]
pub mod rusqlite_impl;
pub mod spk_client;
#[cfg(feature = "sqlx")]
pub mod sqlx_impl;

#[allow(unused_imports)]
#[macro_use]
extern crate alloc;
#[cfg(feature = "rusqlite")]
pub extern crate rusqlite;
#[cfg(feature = "sqlx")]
pub extern crate sqlx;
#[cfg(feature = "serde")]
pub extern crate serde;

Expand Down
11 changes: 6 additions & 5 deletions crates/chain/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ pub trait PersistWith<Db>: Staged + Sized {
) -> Result<(), Self::PersistError>;
}

type FutureResult<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'a>>;
pub type FutureResult<'a, T, E> = Pin<Box<dyn Future<Output = Result<T, E>> + Send + 'a>>;

/// Trait that persists the type with an async `Db`.
#[async_trait::async_trait]
pub trait PersistAsyncWith<Db>: Staged + Sized {
/// Parameters for [`PersistAsyncWith::create`].
type CreateParams;
Expand All @@ -61,16 +62,16 @@ pub trait PersistAsyncWith<Db>: Staged + Sized {
type PersistError;

/// Initialize the `Db` and create `Self`.
fn create(db: &mut Db, params: Self::CreateParams) -> FutureResult<Self, Self::CreateError>;
async fn create(db: &mut Db, params: Self::CreateParams) -> Result<Self, Self::CreateError>;

/// Initialize the `Db` and load a previously-persisted `Self`.
fn load(db: &mut Db, params: Self::LoadParams) -> FutureResult<Option<Self>, Self::LoadError>;
async fn load(db: &mut Db, params: Self::LoadParams) -> Result<Option<Self>, Self::LoadError>;

/// Persist changes to the `Db`.
fn persist<'a>(
async fn persist<'a>(
db: &'a mut Db,
changeset: &'a <Self as Staged>::ChangeSet,
) -> FutureResult<'a, (), Self::PersistError>;
) -> Result<(), Self::PersistError>;
}

/// Represents a persisted `T`.
Expand Down
Loading
Loading