fix(db): db debugging (in progress)
This commit is contained in:
parent
4760364491
commit
dc70316bae
4 changed files with 103 additions and 63 deletions
|
@ -16,7 +16,7 @@ leptos_meta = { version = "0.6" }
|
||||||
leptos_actix = { version = "0.6", optional = true }
|
leptos_actix = { version = "0.6", optional = true }
|
||||||
leptos_router = { version = "0.6" }
|
leptos_router = { version = "0.6" }
|
||||||
wasm-bindgen = "=0.2.99"
|
wasm-bindgen = "=0.2.99"
|
||||||
rusqlite = "0.27.0"
|
rusqlite = { version = "0.27.0", optional = true}
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
uuid = { version = "1.0", features = ["v4"] }
|
uuid = { version = "1.0", features = ["v4"] }
|
||||||
web-sys = { version = "0.3", features = ["Event"] }
|
web-sys = { version = "0.3", features = ["Event"] }
|
||||||
|
@ -40,6 +40,7 @@ ssr = [
|
||||||
"leptos/ssr",
|
"leptos/ssr",
|
||||||
"leptos_meta/ssr",
|
"leptos_meta/ssr",
|
||||||
"leptos_router/ssr",
|
"leptos_router/ssr",
|
||||||
|
"rusqlite"
|
||||||
]
|
]
|
||||||
|
|
||||||
# Override secp256k1's default features
|
# Override secp256k1's default features
|
||||||
|
|
|
@ -8,6 +8,8 @@ use crate::models::item::Item;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
use crate::db::{Database, DbItem};
|
||||||
|
|
||||||
#[derive(Deserialize, Clone, Debug)]
|
#[derive(Deserialize, Clone, Debug)]
|
||||||
struct WikidataSuggestion {
|
struct WikidataSuggestion {
|
||||||
|
@ -35,6 +37,26 @@ pub fn ItemsList(
|
||||||
|
|
||||||
//signal to store the fetched property labels
|
//signal to store the fetched property labels
|
||||||
let (property_labels, set_property_labels) = create_signal(HashMap::<String, String>::new());
|
let (property_labels, set_property_labels) = create_signal(HashMap::<String, String>::new());
|
||||||
|
|
||||||
|
let db_path = "items.db"; // path to the database file
|
||||||
|
let db = Database::new(db_path).unwrap();
|
||||||
|
db.create_schema().unwrap();
|
||||||
|
|
||||||
|
let db_items = db.get_items().unwrap();
|
||||||
|
let loaded_items: Vec<Item> = db_items.into_iter().map(|db_item| {
|
||||||
|
Item {
|
||||||
|
id: db_item.id,
|
||||||
|
name: db_item.name,
|
||||||
|
description: db_item.description,
|
||||||
|
wikidata_id: db_item.wikidata_id,
|
||||||
|
custom_properties: serde_json::from_str(&db_item.custom_properties).unwrap(),
|
||||||
|
}
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
spawn_local(async move {
|
||||||
|
set_items.set(loaded_items);
|
||||||
|
});
|
||||||
|
|
||||||
// Ensure there's an initial empty row
|
// Ensure there's an initial empty row
|
||||||
if items.get().is_empty() {
|
if items.get().is_empty() {
|
||||||
set_items.set(vec![Item {
|
set_items.set(vec![Item {
|
||||||
|
@ -238,6 +260,16 @@ pub fn ItemsList(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// //update items in the database
|
||||||
|
// let db_item = DbItem {
|
||||||
|
// id: items[index].id.clone(),
|
||||||
|
// name: items[index].name.clone(),
|
||||||
|
// description: items[index].description.clone(),
|
||||||
|
// wikidata_id: items[index].wikidata_id.clone(),
|
||||||
|
// custom_properties: serde_json::to_string(&items[index].custom_properties).unwrap(),
|
||||||
|
// };
|
||||||
|
// db.insert_item(&db_item).unwrap();
|
||||||
|
|
||||||
|
|
||||||
// Automatically add a new row when editing the last row
|
// Automatically add a new row when editing the last row
|
||||||
if index == items.len() - 1 && !value.is_empty() {
|
if index == items.len() - 1 && !value.is_empty() {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
mod db_impl {
|
||||||
use rusqlite::{Connection, Error};
|
use rusqlite::{Connection, Error};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -67,3 +69,7 @@ pub struct DbItem {
|
||||||
pub wikidata_id: Option<String>,
|
pub wikidata_id: Option<String>,
|
||||||
pub custom_properties: String,
|
pub custom_properties: String,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
pub use db_impl::{Database, DbItem};
|
|
@ -2,6 +2,7 @@ pub mod app;
|
||||||
pub mod components;
|
pub mod components;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
pub mod nostr;
|
pub mod nostr;
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
pub mod db;
|
pub mod db;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue