mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 02:11:54 +00:00
12
patch-db-util/Cargo.toml
Normal file
12
patch-db-util/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "patch-db-util"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = "3.2.16"
|
||||
patch-db = { path = "../patch-db" }
|
||||
serde_json = "1.0.85"
|
||||
tokio = { version = "1.20.1", features = ["full"] }
|
||||
46
patch-db-util/src/main.rs
Normal file
46
patch-db-util/src/main.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use std::path::Path;
|
||||
|
||||
use patch_db::json_ptr::{JsonPointer, PtrSegment};
|
||||
use serde_json::Value;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let mut app = clap::App::new("patch-db-util")
|
||||
.subcommand(
|
||||
clap::Command::new("dump").arg(
|
||||
clap::Arg::new("PATH")
|
||||
.required(true)
|
||||
.help("Path to the database file"),
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
clap::Command::new("from-dump").arg(
|
||||
clap::Arg::new("PATH")
|
||||
.required(true)
|
||||
.help("Path to the database file"),
|
||||
),
|
||||
);
|
||||
|
||||
match app.clone().get_matches().subcommand() {
|
||||
Some(("dump", matches)) => {
|
||||
let path = matches.value_of("PATH").unwrap();
|
||||
let db = patch_db::PatchDb::open(path).await.unwrap();
|
||||
let dump = db.dump().await;
|
||||
serde_json::to_writer_pretty(&mut std::io::stdout(), &dump.value).unwrap();
|
||||
println!();
|
||||
}
|
||||
Some(("from-dump", matches)) => {
|
||||
let path = matches.value_of("PATH").unwrap();
|
||||
let value: Value = serde_json::from_reader(&mut std::io::stdin()).unwrap();
|
||||
let db = patch_db::PatchDb::open(path).await.unwrap();
|
||||
db.put(
|
||||
&JsonPointer::<&str, (&[PtrSegment], &[PtrSegment])>::default(),
|
||||
&value,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
_ => app.print_long_help().unwrap(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user