2024-05-17 12:00:37 -05:00
|
|
|
use crate::prelude::*;
|
|
|
|
use sea_orm::{Database, DatabaseConnection};
|
|
|
|
use thiserror::Error;
|
2024-05-14 12:28:27 -05:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct State {
|
2024-05-17 12:00:37 -05:00
|
|
|
db: DatabaseConnection,
|
2024-05-14 12:28:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl State {
|
2024-05-17 12:00:37 -05:00
|
|
|
pub async fn try_new(database_connection_string: &str) -> Result<Self, NewStateError> {
|
|
|
|
Ok(Self {
|
|
|
|
db: Database::connect(database_connection_string).await?,
|
|
|
|
})
|
2024-05-14 12:28:27 -05:00
|
|
|
}
|
|
|
|
}
|
2024-05-15 16:48:23 -05:00
|
|
|
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum NewStateError {
|
2024-05-17 12:00:37 -05:00
|
|
|
#[error("database error: {0}")]
|
|
|
|
Database(#[from] sea_orm::DbErr),
|
2024-05-15 16:48:23 -05:00
|
|
|
}
|