#Has anyone succeeded with Postgres + Dioxus?
1 messages ยท Page 1 of 1 (latest)
Are you trying to compile for WASM?
Perhaps you have "fullstack" Dioxus app? In which can you need to gate the postgres dependency behind the "server" feature.
Trying to connect to Postgres directly from the frontend of web app won't work because the Postgres protocol runs over TCP and there's no way to open a TCP socket from within a browser.
(Dioxus Desktop should work, but I'm assuming that's not what you're compiling here, becuase I don't think you'd be running into this error)
I do have a fullstack app! How would i go about gating the postgres dependency behind the server feature?
in dependencies postgres = { version = "...", optional = true }
In features server = ["dep:postgres", ...]
Fill in the blanks rather than using literal ...
Doing that and then running dx server --server to use the postgres code got it to work!
I appreciate the help Nico!
sorry to re-open this, but the above results in me getting a new error, that I'm not able to solve myself
20:39:28 [dev] Build completed successfully in 521ms, launching app! ๐ซ
20:39:28 [server] WARN No index.html found in public directory, using default index.html
20:39:29 [server] WARN No index.html found in public directory, using default index.html
20:39:29 [server] thread 'main' (16317) panicked at /Users/jturner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-server-0.7.2/src/launch.rs:143:10:
20:39:29 [server] called Result::unwrap() on an Err value: Failed to bind to address 127.0.0.1:49240
20:39:29 [server] Caused by:
20:39:29 [server] Address already in use (os error 48)
20:39:29 [server] note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
20:39:29 [dev] Application [server] exited with error: exit status: 101
When i went through to find what was on 127.0.0.1:49240, it was the app itself, which I found out by killing the process and getting 20:41:27 [dev] Application [server] exited with error: signal: 9 (SIGKILL)
when the app is up, I can still route from page to page, but interacting with buttons and forms no longer works
so I ran dx doctor and found wasm-opt was not installed, so i installed that and it removed the errors, but only when I am not using the postgres crate to connect to the db
however, interactivity is still down
atm I'm just messing around with some of the dioxus examples, so the code is fairly simple;
fn FrequencyComponent() -> Element {
let mut count = use_signal(|| 0);
rsx! {
div {
h1 { "freq: {count}" }
button { onclick: move |_| count += 1, " + " }
button { onclick: move |_| count -= 1, " - " }
}
}
}
#[component]
fn DurationComponent() -> Element {
let mut duration = use_signal(|| String::from(""));
rsx!(
div{
h1{"Duration: {duration}"}
input {
value: "{duration}",
oninput: move |e| duration.set(e.value())
}
}
)
}