Clear out DB before importing
parent
9019267d7f
commit
b15b1f23fd
|
@ -102,7 +102,7 @@ checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "j_db"
|
name = "j_db"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"json",
|
"json",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "j_db"
|
name = "j_db"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
authors = ["Joey Hines <joey@ahines.net>"]
|
authors = ["Joey Hines <joey@ahines.net>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A good enough (TM) embedded Rust DB* and ORM*"
|
description = "A good enough (TM) embedded Rust DB* and ORM*"
|
||||||
|
|
|
@ -217,6 +217,7 @@ impl Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn import_db(&self, json: JsonValue) -> Result<()> {
|
pub fn import_db(&self, json: JsonValue) -> Result<()> {
|
||||||
|
self.db.clear()?;
|
||||||
for model in json["global"].members() {
|
for model in json["global"].members() {
|
||||||
let id_bytes = model["id"].as_u64().unwrap().to_be_bytes();
|
let id_bytes = model["id"].as_u64().unwrap().to_be_bytes();
|
||||||
self.db.insert(id_bytes, model.to_string().as_bytes())?;
|
self.db.insert(id_bytes, model.to_string().as_bytes())?;
|
||||||
|
|
Loading…
Reference in New Issue