use leptos::*; use crate::db::crud::{{ schema.short_name }}::{{ schema.short_name | pascal }}; #[server({{ endpoint_name }}, "/api")] pub async fn {{ function_name }}( {%- for param in schema.params %} {{ param.name }}: {{ param.type_ }}, {%- if loop.last %} {% endif -%} {%- endfor -%} ) -> Result<{{ schema.output_type }}, ServerFnError> { use surrealdb::{engine::remote::ws::Ws, Surreal, opt::auth::Root}; use crate::db::crud::{{ schema.short_name }}::{{ schema.name }}; let db = Surreal::new::("localhost:8000") .await .map_err(|_| ServerFnError::ServerError("Cannot open connection to SurrealDB".to_string()))?; db .signin(Root { username: "root", password: "root", }) .await .map_err(|_| ServerFnError::ServerError("Cannot signin to SurrealDB".to_string()))?; db .use_ns("test") .use_db("test") .await .map_err(|_| ServerFnError::ServerError("Cannot use namespace and database".to_string()))?; {{ schema.name }}({{ [['&db'], schema.params | map(attribute="name")] | flatten | join(", ") }}) .await .map_err(|_| ServerFnError::ServerError("Cannot apply function {{ schema.name }}".to_string()))?; Ok(()) }