Compare commits
3 commits
a8d8e9a131
...
a35d4d557d
Author | SHA1 | Date | |
---|---|---|---|
a35d4d557d | |||
2bcdea79dc | |||
a379e93f44 |
3 changed files with 39 additions and 17 deletions
|
@ -84,8 +84,19 @@ pub fn ItemsList(
|
|||
// Signal to store the fetched property labels
|
||||
let (property_labels, set_property_labels) = create_signal(HashMap::<String, String>::new());
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
fn get_current_url() -> String {
|
||||
window()
|
||||
use leptos::use_context;
|
||||
use actix_web::HttpRequest;
|
||||
|
||||
use_context::<HttpRequest>()
|
||||
.map(|req| req.uri().to_string())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
fn get_current_url() -> String {
|
||||
web_sys::window()
|
||||
.and_then(|win| win.location().href().ok())
|
||||
.unwrap_or_else(|| "".to_string())
|
||||
}
|
||||
|
@ -190,10 +201,10 @@ pub fn ItemsList(
|
|||
|
||||
let item_to_send = ItemToSend {
|
||||
url: current_url.to_string(),
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
description: item.description,
|
||||
wikidata_id: item.wikidata_id,
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
description: item.description,
|
||||
wikidata_id: item.wikidata_id,
|
||||
custom_properties, // Use the serialized string
|
||||
};
|
||||
|
||||
|
|
24
src/db.rs
24
src/db.rs
|
@ -36,17 +36,22 @@ mod db_impl {
|
|||
name TEXT NOT NULL UNIQUE,
|
||||
global_usage_count INTEGER DEFAULT 0
|
||||
);"
|
||||
)?;
|
||||
).map_err(|e| {
|
||||
eprintln!("Failed creating properties table: {}", e);
|
||||
e
|
||||
})?;
|
||||
|
||||
// 2. URLs table
|
||||
conn.execute_batch(
|
||||
"CREATE TABLE IF NOT EXISTS urls (
|
||||
id INTEGER PRIMARY KEY,
|
||||
url TEXT NOT NULL UNIQUE, // Enforce unique URLs
|
||||
url TEXT NOT NULL UNIQUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);",
|
||||
)?;
|
||||
logging::log!("URLs table created or verified");
|
||||
).map_err(|e| {
|
||||
eprintln!("Failed creating urls table: {}", e);
|
||||
e
|
||||
})?;
|
||||
|
||||
// 3. Items table
|
||||
conn.execute_batch(
|
||||
|
@ -58,8 +63,10 @@ mod db_impl {
|
|||
wikidata_id TEXT,
|
||||
FOREIGN KEY (url_id) REFERENCES urls(id) ON DELETE CASCADE
|
||||
);",
|
||||
)?;
|
||||
logging::log!("Items table updated with foreign key to URLs table");
|
||||
).map_err(|e| {
|
||||
eprintln!("Failed creating items table: {}", e);
|
||||
e
|
||||
})?;
|
||||
|
||||
// 4. Junction table for custom properties
|
||||
conn.execute_batch(
|
||||
|
@ -71,7 +78,10 @@ mod db_impl {
|
|||
FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (property_id) REFERENCES properties(id) ON DELETE CASCADE
|
||||
);"
|
||||
)?;
|
||||
).map_err(|e| {
|
||||
eprintln!("Failed creating item_properties table: {}", e);
|
||||
e
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -18,15 +18,16 @@ async fn main() -> std::io::Result<()> {
|
|||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
|
||||
// Load configuration
|
||||
let conf = get_configuration(None).await.unwrap();
|
||||
let addr = conf.leptos_options.site_addr;
|
||||
|
||||
// Initialize the database
|
||||
let db = Database::new("compareware.db").unwrap();
|
||||
db.create_schema().await.unwrap(); // Ensure the schema is created
|
||||
let db = Arc::new(Mutex::new(db)); // Wrap the database in an Arc<Mutex<T>> for shared state
|
||||
println!("Schema created successfully!");
|
||||
|
||||
// Load configuration
|
||||
let conf = get_configuration(None).await.unwrap();
|
||||
let addr = conf.leptos_options.site_addr;
|
||||
|
||||
|
||||
// Generate the list of routes in your Leptos App
|
||||
let routes = generate_route_list(App);
|
||||
|
|
Loading…
Add table
Reference in a new issue