2025-05-12 08:49:51 +09:00
|
|
|
use crate::error::Error;
|
2025-05-12 20:29:46 +09:00
|
|
|
use sea_orm::{ConnectOptions, Database, DatabaseConnection, DbErr};
|
2025-05-12 08:49:51 +09:00
|
|
|
|
2025-05-12 20:29:46 +09:00
|
|
|
pub trait GlobalDatabase {
|
2025-05-13 06:03:16 +09:00
|
|
|
fn get_database(&self) -> Option<&DatabaseConnection>;
|
|
|
|
async fn get_or_try_init_database(&self) -> Result<&DatabaseConnection, Error>;
|
|
|
|
async fn get_or_try_init_database_with_connect_options<T>(&self, options: T) -> Result<&DatabaseConnection, Error> where
|
2025-05-12 20:29:46 +09:00
|
|
|
T: Into<ConnectOptions>;
|
2025-05-12 08:49:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
}
|