-
I'm trying to use SurrealDB from within a server function with leptos, but introducing any SurrealDB calls gives me a compilation error. After running use surrealdb::Surreal;
use surrealdb::engine::remote::ws::Ws;
...
#[server(AddTodo, "/api")]
pub async fn add_todo(title: String) -> Result<String, ServerFnError> {
let db = Surreal::new::<Ws>("127.0.0.1:8000").await?;
Ok(format!("Added {}", title))
}
#[component]
fn AddTodo() -> impl IntoView {
let add_todo = create_server_action::<AddTodo>();
// holds the latest *returned* value from the server
let value = add_todo.value();
// check if the server has returned an error
let has_error = move || value.with(|val| matches!(val, Some(Err(_))));
view! {
<div>{value}</div>
<ActionForm action=add_todo>
<label>
"Add a Todo"
// `title` matches the `title` argument to `add_todo`
<input type="text" name="title"/>
</label>
<input type="submit" value="Add"/>
</ActionForm>
}
}
I don't think it should be compiling ring for the browser at all, but I'm not sure how to debug this. |
Beta Was this translation helpful? Give feedback.
Answered by
tqwewe
Oct 31, 2023
Replies: 1 comment 1 reply
-
You need to add surrealdb as an optional dependency which is only used with the surrealdb = { version = "*", optional = true }
[features]
ssr = [
"dep:surrealdb"
] |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
lukej57
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to add surrealdb as an optional dependency which is only used with the
ssr
feature flag.