From 1e1b74473a84a0c96e1c5ff32f774fa59fd889a1 Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Wed, 9 Dec 2020 22:58:58 +0100 Subject: [PATCH] [feat] dex: add db dunp_v1 --- rust-bins/duniter-dbex/src/cli.rs | 4 +++- rust-bins/duniter-dbex/src/main.rs | 33 ++++++++++++++++++--------- rust-libs/duniter-dbs/src/lib.rs | 1 + rust-libs/duniter-dbs/src/open_dbs.rs | 14 +++++++----- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/rust-bins/duniter-dbex/src/cli.rs b/rust-bins/duniter-dbex/src/cli.rs index e98ee25e2..aa8aa5420 100644 --- a/rust-bins/duniter-dbex/src/cli.rs +++ b/rust-bins/duniter-dbex/src/cli.rs @@ -28,7 +28,7 @@ pub struct Opt { pub home: Option<PathBuf>, /// database - #[structopt(default_value = "bc_v1", possible_values = &["bc_v1", "bc_v2", "gva_v1", "txs_mp_v2"])] + #[structopt(default_value = "bc_v1", possible_values = &["bc_v1", "bc_v2", "dunp_v1", "gva_v1", "txs_mp_v2"])] pub database: Database, #[structopt(subcommand)] @@ -39,6 +39,7 @@ pub struct Opt { pub enum Database { BcV1, BcV2, + DunpV1, GvaV1, TxsMpV2, } @@ -50,6 +51,7 @@ impl FromStr for Database { match s { "bc_v1" => Ok(Self::BcV1), "bc_v2" => Ok(Self::BcV2), + "dunp_v1" => Ok(Self::DunpV1), "gva_v1" => Ok(Self::GvaV1), "txs_mp_v2" => Ok(Self::TxsMpV2), _ => unreachable!(), diff --git a/rust-bins/duniter-dbex/src/main.rs b/rust-bins/duniter-dbex/src/main.rs index ddd314b8b..7002d803e 100644 --- a/rust-bins/duniter-dbex/src/main.rs +++ b/rust-bins/duniter-dbex/src/main.rs @@ -31,13 +31,13 @@ use self::cli::{Database, Opt, OutputFormat, SubCommand}; use self::stringify_json_value::stringify_json_value; use anyhow::anyhow; use comfy_table::Table; -use duniter_dbs::databases::bc_v2::{BcV2Db, BcV2DbWritable}; use duniter_dbs::databases::{ bc_v1::{BcV1Db, BcV1DbWritable}, + bc_v2::{BcV2Db, BcV2DbWritable}, + dunp_v1::{DunpV1Db, DunpV1DbWritable}, gva_v1::{GvaV1Db, GvaV1DbWritable}, txs_mp_v2::{TxsMpV2Db, TxsMpV2DbWritable}, }; -use duniter_dbs::kv_typed::backend::sled; use duniter_dbs::kv_typed::prelude::*; use duniter_dbs::prelude::*; use duniter_dbs::regex::Regex; @@ -100,23 +100,34 @@ fn main() -> anyhow::Result<()> { open_db_start_time, ), Database::BcV2 => apply_subcommand( - BcV2Db::<Sled>::open( - sled::Config::default().path(data_path.as_path().join("bc_v2_sled")), - )?, + BcV2Db::<Sled>::open(Sled::gen_backend_conf( + BcV2Db::<Sled>::NAME, + Some(profile_path.as_path()), + ))?, + opt.cmd, + open_db_start_time, + ), + Database::DunpV1 => apply_subcommand( + DunpV1Db::<Sled>::open(Sled::gen_backend_conf( + DunpV1Db::<Sled>::NAME, + Some(profile_path.as_path()), + ))?, opt.cmd, open_db_start_time, ), Database::GvaV1 => apply_subcommand( - GvaV1Db::<Sled>::open( - sled::Config::default().path(data_path.as_path().join("gva_v1_sled")), - )?, + GvaV1Db::<Sled>::open(Sled::gen_backend_conf( + GvaV1Db::<Sled>::NAME, + Some(profile_path.as_path()), + ))?, opt.cmd, open_db_start_time, ), Database::TxsMpV2 => apply_subcommand( - TxsMpV2Db::<Sled>::open( - sled::Config::default().path(data_path.as_path().join("txs_mp_v2_sled")), - )?, + TxsMpV2Db::<Sled>::open(Sled::gen_backend_conf( + TxsMpV2Db::<Sled>::NAME, + Some(profile_path.as_path()), + ))?, opt.cmd, open_db_start_time, ), diff --git a/rust-libs/duniter-dbs/src/lib.rs b/rust-libs/duniter-dbs/src/lib.rs index a9e2d3dd4..ade5c98f0 100644 --- a/rust-libs/duniter-dbs/src/lib.rs +++ b/rust-libs/duniter-dbs/src/lib.rs @@ -40,6 +40,7 @@ pub use kv_typed; // Prelude pub mod prelude { + pub use crate::open_dbs::BackendConf; pub use crate::DuniterDbs; #[cfg(feature = "explorer")] pub use kv_typed::explorer::{ diff --git a/rust-libs/duniter-dbs/src/open_dbs.rs b/rust-libs/duniter-dbs/src/open_dbs.rs index 014d5aaf6..cc07815fa 100644 --- a/rust-libs/duniter-dbs/src/open_dbs.rs +++ b/rust-libs/duniter-dbs/src/open_dbs.rs @@ -23,25 +23,27 @@ use crate::*; pub fn open_dbs<B: BackendConf>( home_path_opt: Option<&Path>, ) -> (crate::databases::bc_v2::BcV2Db<B>, DuniterDbs<B>) { - let bc_db = - crate::databases::bc_v2::BcV2Db::<B>::open(B::gen_backend_conf("bc_v2", home_path_opt)) - .expect("fail to open BcV2 DB"); + let bc_db = crate::databases::bc_v2::BcV2Db::<B>::open(B::gen_backend_conf( + crate::databases::bc_v2::BcV2Db::<B>::NAME, + home_path_opt, + )) + .expect("fail to open BcV2 DB"); let dbs = DuniterDbs { bc_db_ro: bc_db.get_ro_handler(), cm_db: crate::databases::cm_v1::CmV1Db::<Mem>::open(MemConf::default()) .expect("fail to open CmV1 DB"), dunp_db: crate::databases::dunp_v1::DunpV1Db::<B>::open(B::gen_backend_conf( - "dunp_v1", + crate::databases::dunp_v1::DunpV1Db::<B>::NAME, home_path_opt, )) .expect("fail to open Dunp DB"), gva_db: crate::databases::gva_v1::GvaV1Db::<B>::open(B::gen_backend_conf( - "gva_v1", + crate::databases::gva_v1::GvaV1Db::<B>::NAME, home_path_opt, )) .expect("fail to open Gva DB"), txs_mp_db: crate::databases::txs_mp_v2::TxsMpV2Db::<B>::open(B::gen_backend_conf( - "txs_mp_v2", + crate::databases::txs_mp_v2::TxsMpV2Db::<B>::NAME, home_path_opt, )) .expect("fail to open TxsMp DB"), -- GitLab