mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-13 22:06:30 +01:00
32 lines
790 B
Rust
32 lines
790 B
Rust
use std::sync::Arc;
|
|
|
|
use common::{storage::db::SurrealDbClient, utils::config::AppConfig};
|
|
|
|
#[derive(Clone)]
|
|
pub struct ApiState {
|
|
pub db: Arc<SurrealDbClient>,
|
|
}
|
|
|
|
impl ApiState {
|
|
pub async fn new(config: &AppConfig) -> Result<Self, Box<dyn std::error::Error>> {
|
|
let surreal_db_client = Arc::new(
|
|
SurrealDbClient::new(
|
|
&config.surrealdb_address,
|
|
&config.surrealdb_username,
|
|
&config.surrealdb_password,
|
|
&config.surrealdb_namespace,
|
|
&config.surrealdb_database,
|
|
)
|
|
.await?,
|
|
);
|
|
|
|
surreal_db_client.ensure_initialized().await?;
|
|
|
|
let app_state = ApiState {
|
|
db: surreal_db_client.clone(),
|
|
};
|
|
|
|
Ok(app_state)
|
|
}
|
|
}
|