* wip: openssl autodetection * add voltaile read inside of asset fn * support xcode 15 for --device * vendor openssl on android * Smaller width TUI * switch to anyhow for the entire CLI * add backtrace and print double printing of cargo_metadata errors * add some padding to multi-line anyhow error * check semvers * don't open if not interactive * set the tailwind current_dir so it doesn't twitch * get the oboe demo working * copy the c++ library on android * cleanup env vars * add depinfo watcher * fix stale hotpatches and crate count * add musl support * remove outdated autofmt test * update scanner app * add hotdog app and bundle to ci * upload dx on every branch * collapse mobile into desktop * `dx doctor` command * windows command files * no pipe on doctor * fix ci? * fix links * fix ci * use main instead of nightly * bump node * build cli for host * cargo doc * prep dog_app for bundle * package hotdog * no bundle or nightly cli * comment out nightly cli * add quotes to linker files
44 lines
1.2 KiB
Rust
44 lines
1.2 KiB
Rust
use dioxus::prelude::*;
|
|
|
|
#[cfg(feature = "server")]
|
|
thread_local! {
|
|
static DB: rusqlite::Connection = {
|
|
let conn = rusqlite::Connection::open("hotdogdb/hotdog.db").expect("Failed to open database");
|
|
|
|
conn.execute_batch(
|
|
"CREATE TABLE IF NOT EXISTS dogs (
|
|
id INTEGER PRIMARY KEY,
|
|
url TEXT NOT NULL
|
|
);",
|
|
).unwrap();
|
|
|
|
conn
|
|
};
|
|
}
|
|
|
|
#[server(endpoint = "list_dogs")]
|
|
pub async fn list_dogs() -> Result<Vec<(usize, String)>, ServerFnError> {
|
|
let dogs = DB.with(|f| {
|
|
f.prepare("SELECT id, url FROM dogs ORDER BY id DESC LIMIT 10")
|
|
.unwrap()
|
|
.query_map([], |row| Ok((row.get(0)?, row.get(1)?)))
|
|
.unwrap()
|
|
.map(|r| r.unwrap())
|
|
.collect()
|
|
});
|
|
|
|
Ok(dogs)
|
|
}
|
|
|
|
#[server(endpoint = "remove_dog")]
|
|
pub async fn remove_dog(id: usize) -> Result<(), ServerFnError> {
|
|
DB.with(|f| f.execute("DELETE FROM dogs WHERE id = ?1", [&id]))?;
|
|
Ok(())
|
|
}
|
|
|
|
#[server(endpoint = "save_dog")]
|
|
pub async fn save_dog(image: String) -> Result<(), ServerFnError> {
|
|
_ = DB.with(|f| f.execute("INSERT INTO dogs (url) VALUES (?1)", [&image]));
|
|
Ok(())
|
|
}
|