onboarding.rs
1 use log::info; 2 use once_cell::sync::Lazy; 3 use serde::{Deserialize, Serialize}; 4 use surrealdb::{ 5 engine::local::{Db, SpeeDb}, 6 Surreal, 7 }; 8 9 static DB: Lazy<Surreal<Db>> = Lazy::new(|| Surreal::init()); 10 11 #[derive(Debug, Clone, Serialize, Deserialize)] 12 pub struct Person { 13 pub name: String, 14 } 15 16 pub async fn init_app(app_document_path: String) -> Result<(), anyhow::Error> { 17 flutter_rust_bridge::setup_default_user_utils(); 18 19 info!("Initializing app..."); 20 DB.connect::<SpeeDb>(app_document_path + "/finedge/db") 21 .await?; 22 DB.use_ns("finedge_app").use_db("finedge").await?; 23 24 DB.update::<Option<Person>>(("person", "arian")) 25 .content(Person { 26 name: "Arian".to_string(), 27 }) 28 .await?; 29 30 Ok(()) 31 } 32 33 pub async fn greet() -> String { 34 let person = DB 35 .select::<Option<Person>>(("person", "arian")) 36 .await 37 .unwrap(); 38 39 format!("Hello, {}!", person.unwrap().name) 40 }