Skip to content

Commit

Permalink
add sled
Browse files Browse the repository at this point in the history
  • Loading branch information
antonilol committed Jul 13, 2024
1 parent 8e5a1e9 commit ed10e34
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 10 deletions.
98 changes: 93 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ edition = "2021"
build = "build.rs"

[features]
default = ["metrics", "rocksdb", "redb"]
default = ["metrics", "rocksdb", "redb", "sled"]
metrics = ["prometheus", "tiny_http"]
metrics_process = ["prometheus/process"]
rocksdb = ["dep:electrs-rocksdb"]
redb = ["dep:redb"]
sled = ["dep:sled"]

[package.metadata.configure_me]
spec = "internal/config_specification.toml"
Expand All @@ -41,6 +42,7 @@ serde_json = "1.0"
signal-hook = "0.3"
tiny_http = { version = "0.12", optional = true }
redb = { version = "2.1.0", optional = true }
sled = { version = "0.34.7", optional = true }

[dependencies.electrs-rocksdb]
version = "0.19.0-e3"
Expand Down
2 changes: 1 addition & 1 deletion internal/config_specification.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ doc = "network magic for custom signet network in hex format, as found in Bitcoi
[[param]]
name = "database"
type = "crate::config::DatabaseType"
doc = "Select database type ('rocksdb' or 'redb')"
doc = "Select database type ('rocksdb', 'redb' or 'sled')"
default = "Default::default()"
5 changes: 4 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub enum DatabaseType {
#[default]
RocksDB,
ReDB,
Sled,
}

impl FromStr for DatabaseType {
Expand All @@ -135,14 +136,15 @@ impl FromStr for DatabaseType {
Ok(match s {
"rocksdb" => Self::RocksDB,
"redb" => Self::ReDB,
"sled" => Self::Sled,
_ => return Err(UnknownDatabaseTypeError(s.to_owned())),
})
}
}

impl ::configure_me::parse_arg::ParseArgFromStr for DatabaseType {
fn describe_type<W: fmt::Write>(mut writer: W) -> fmt::Result {
write!(writer, "either 'rocksdb' or 'redb'")
write!(writer, "either 'rocksdb', 'redb' or 'sled'")
}
}

Expand All @@ -151,6 +153,7 @@ impl fmt::Display for DatabaseType {
match self {
Self::RocksDB => write!(f, "rocksdb"),
Self::ReDB => write!(f, "redb"),
Self::Sled => write!(f, "sled"),
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ pub mod rocksdb;
#[cfg(feature = "redb")]
pub mod redb;

#[cfg(not(any(feature = "rocksdb", feature = "redb",)))]
#[cfg(feature = "sled")]
pub mod sled;

#[cfg(not(any(feature = "rocksdb", feature = "redb", feature = "sled",)))]
compile_error!(
"Tried to build electrs without database, but at least one is needed. \
Enable at least one of the following features: 'rocksdb', 'redb'."
Enable at least one of the following features: 'rocksdb', 'redb', 'sled'."
);

use anyhow::Result;
Expand Down
Loading

0 comments on commit ed10e34

Please sign in to comment.