use serde::{Deserialize, Serialize}; use surrealdb::{sql::Thing, Connection, Result, Surreal}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct {{ struct_name }} { {%- for field in struct_fields %} pub {{ field.name }}: {{ field.type_str }}, {%- endfor %} } pub async fn get_all_{{ table_name }}(db: &'_ Surreal) -> Result> { let result = db.select("{{ table_name }}").await?; Ok(result) } pub async fn get_{{ table_name }}(db: &'_ Surreal, id: &str) -> Result<{{ struct_name }}> { let result = db.select(("{{ table_name }}", id)).await?; Ok(result) } pub async fn find_{{ table_name }}(db: &'_ Surreal, id: &str) -> Result> { let result = db.select(("{{ table_name }}", id)).await?; Ok(result) } {%- if table_name != "script_migration" %} pub async fn create_{{ table_name }}(db: &'_ Surreal, data: {{ struct_name }}) -> Result<{{ struct_name }}> { let result = db.create("{{ table_name }}").content(data).await?; Ok(result) } pub async fn update_{{ table_name }}(db: &'_ Surreal, id: &str, data: {{ struct_name }}) -> Result> { let result = db.update(("{{ table_name }}", id)).content(data).await?; Ok(result) } pub async fn delete_all_{{ table_name }}(db: &'_ Surreal) -> Result> { let result = db.delete("{{ table_name }}").await?; Ok(result) } pub async fn delete_{{ table_name }}(db: &'_ Surreal, id: &str) -> Result> { let result = db.delete(("{{ table_name }}", id)).await?; Ok(result) } {%- endif -%}