feat(db): enable db to update items keeping track of the item's id
This commit is contained in:
parent
3ed12c80a6
commit
fc13b0dae6
1 changed files with 18 additions and 12 deletions
14
src/db.rs
14
src/db.rs
|
@ -16,7 +16,7 @@ mod db_impl {
|
|||
// Create a new database connection
|
||||
pub fn new(db_path: &str) -> Result<Self, Error> {
|
||||
let conn = Connection::open(db_path)?;
|
||||
logging::log!("Database connection established at: {}", db_path); // Log with Leptos
|
||||
logging::log!("Database connection established at: {}", db_path);
|
||||
Ok(Database {
|
||||
conn: Arc::new(Mutex::new(conn)),
|
||||
})
|
||||
|
@ -34,7 +34,7 @@ mod db_impl {
|
|||
custom_properties TEXT
|
||||
);",
|
||||
)?;
|
||||
logging::log!("Database schema created or verified"); // Log with Leptos
|
||||
logging::log!("Database schema created or verified");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,13 @@ mod db_impl {
|
|||
let conn = self.conn.lock().await;
|
||||
let wikidata_id = item.wikidata_id.as_ref().map(|s| s.as_str()).unwrap_or("");
|
||||
conn.execute(
|
||||
"INSERT INTO items (id, name, description, wikidata_id, custom_properties) VALUES (?, ?, ?, ?, ?);",
|
||||
"INSERT INTO items (id, name, description, wikidata_id, custom_properties)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
name = excluded.name,
|
||||
description = excluded.description,
|
||||
wikidata_id = excluded.wikidata_id,
|
||||
custom_properties = excluded.custom_properties;",
|
||||
&[
|
||||
&item.id,
|
||||
&item.name,
|
||||
|
@ -52,7 +58,7 @@ mod db_impl {
|
|||
&item.custom_properties,
|
||||
],
|
||||
)?;
|
||||
logging::log!("Item inserted: {}", item.id); // Log with Leptos
|
||||
logging::log!("Item inserted: {}", item.id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue