fixes
This commit is contained in:
parent
2d5541b0e7
commit
4f5d17d464
6 changed files with 33 additions and 12 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1060,6 +1060,7 @@ dependencies = [
|
||||||
"hexdump",
|
"hexdump",
|
||||||
"log",
|
"log",
|
||||||
"mktemp",
|
"mktemp",
|
||||||
|
"pretty_env_logger",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"sled",
|
"sled",
|
||||||
]
|
]
|
||||||
|
|
|
@ -27,9 +27,10 @@ sled = "0.34"
|
||||||
|
|
||||||
# cli deps
|
# cli deps
|
||||||
clap = { version = "3.1.18", optional = true, features = ["derive", "env"] }
|
clap = { version = "3.1.18", optional = true, features = ["derive", "env"] }
|
||||||
|
pretty_env_logger = { version = "0.4", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
mktemp = "0.4"
|
mktemp = "0.4"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
cli = ["clap"]
|
cli = ["clap", "pretty_env_logger"]
|
||||||
|
|
|
@ -25,6 +25,8 @@ struct Args {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
pretty_env_logger::init();
|
||||||
|
|
||||||
match do_conversion(args) {
|
match do_conversion(args) {
|
||||||
Ok(()) => println!("Success!"),
|
Ok(()) => println!("Success!"),
|
||||||
Err(e) => eprintln!("Error: {}", e),
|
Err(e) => eprintln!("Error: {}", e),
|
||||||
|
|
|
@ -198,16 +198,25 @@ impl Db {
|
||||||
|
|
||||||
let ex_tree = other.open_tree(&name)?;
|
let ex_tree = other.open_tree(&name)?;
|
||||||
|
|
||||||
|
let tx_res = self.transaction(|mut tx| {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for item in ex_tree.iter()? {
|
for item in ex_tree.iter()? {
|
||||||
let (k, v) = item?;
|
let (k, v) = item?;
|
||||||
tree.insert(k, v)?;
|
tx.insert(&tree, k, v)?;
|
||||||
i += 1;
|
i += 1;
|
||||||
if i % 1000 == 0 {
|
if i % 1000 == 0 {
|
||||||
println!("{}: imported {}", name, i);
|
println!("{}: imported {}", name, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("{}: finished importing, {} items", name, i);
|
Ok::<_, TxError<()>>(i)
|
||||||
|
});
|
||||||
|
let total = match tx_res {
|
||||||
|
Err(TxError::Db(e)) => return Err(e),
|
||||||
|
Err(TxError::Abort(_)) => unreachable!(),
|
||||||
|
Ok(x) => x,
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("{}: finished importing, {} items", name, total);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,7 +230,10 @@ impl<'a, 'db> ITx for LmdbTx<'a, 'db> {
|
||||||
fn get(&self, tree: usize, key: &[u8]) -> Result<Option<Value<'_>>> {
|
fn get(&self, tree: usize, key: &[u8]) -> Result<Option<Value<'_>>> {
|
||||||
let tree = self.get_tree(tree)?;
|
let tree = self.get_tree(tree)?;
|
||||||
match tree.get(&self.tx, &key)? {
|
match tree.get(&self.tx, &key)? {
|
||||||
Some(v) => Ok(Some(Value(Box::new(v)))),
|
Some(v) => {
|
||||||
|
let v: &'_ [u8] = v;
|
||||||
|
Ok(Some(v.into()))
|
||||||
|
}
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -372,7 +375,11 @@ where
|
||||||
match iter_ref.unwrap().next() {
|
match iter_ref.unwrap().next() {
|
||||||
None => None,
|
None => None,
|
||||||
Some(Err(e)) => Some(Err(e.into())),
|
Some(Err(e)) => Some(Err(e.into())),
|
||||||
Some(Ok((k, v))) => Some(Ok((k.into(), v.into()))),
|
Some(Ok((k, v))) => {
|
||||||
|
let k: &'a [u8] = k;
|
||||||
|
let v: &'a [u8] = v;
|
||||||
|
Some(Ok((k.into(), v.into())))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,7 @@ impl IDb for SqliteDb {
|
||||||
while let Some(row) = rows.next()? {
|
while let Some(row) = rows.next()? {
|
||||||
let name = row.get::<_, String>(0)?;
|
let name = row.get::<_, String>(0)?;
|
||||||
let name = name.replace("_COLON_", ":");
|
let name = name.replace("_COLON_", ":");
|
||||||
|
let name = name.strip_prefix("tree_").unwrap().to_string();
|
||||||
trees.push(name);
|
trees.push(name);
|
||||||
}
|
}
|
||||||
Ok(trees)
|
Ok(trees)
|
||||||
|
|
Loading…
Reference in a new issue