Clear out DB before importing

main
Joey Hines 2024-02-03 11:11:11 -07:00
parent 9019267d7f
commit b15b1f23fd
Signed by: joeyahines
GPG Key ID: 995E531F7A569DDB
3 changed files with 3 additions and 2 deletions

2
Cargo.lock generated
View File

@ -102,7 +102,7 @@ checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
[[package]]
name = "j_db"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"byteorder",
"json",

View File

@ -1,6 +1,6 @@
[package]
name = "j_db"
version = "0.1.0"
version = "0.1.1"
authors = ["Joey Hines <joey@ahines.net>"]
edition = "2021"
description = "A good enough (TM) embedded Rust DB* and ORM*"

View File

@ -217,6 +217,7 @@ impl Database {
}
pub fn import_db(&self, json: JsonValue) -> Result<()> {
self.db.clear()?;
for model in json["global"].members() {
let id_bytes = model["id"].as_u64().unwrap().to_be_bytes();
self.db.insert(id_bytes, model.to_string().as_bytes())?;