2024-11-30 19:36:20 +03:00
|
|
|
pub mod interaction;
|
2024-12-02 23:56:43 +03:00
|
|
|
pub mod message;
|
2024-11-30 19:36:20 +03:00
|
|
|
pub mod post;
|
|
|
|
pub mod user;
|
|
|
|
|
2024-12-02 23:56:43 +03:00
|
|
|
use std::time::Duration;
|
2024-12-01 22:17:38 +03:00
|
|
|
|
2024-12-02 23:56:43 +03:00
|
|
|
use sea_orm::{Database, DatabaseConnection};
|
2024-11-26 22:30:25 +03:00
|
|
|
use tokio::time::sleep;
|
|
|
|
|
2024-12-02 23:56:43 +03:00
|
|
|
use crate::DatabaseConfig;
|
2024-11-26 22:30:25 +03:00
|
|
|
|
2024-12-02 23:56:43 +03:00
|
|
|
pub async fn establish_connection() -> DatabaseConnection {
|
2024-11-26 22:30:25 +03:00
|
|
|
let database_config = DatabaseConfig::default();
|
2024-12-02 23:56:43 +03:00
|
|
|
let connection_string = format!(
|
|
|
|
"{}://{}:{}@{}/{}",
|
|
|
|
database_config.backend,
|
|
|
|
database_config.username,
|
|
|
|
database_config.password,
|
|
|
|
database_config.address,
|
|
|
|
database_config.database
|
|
|
|
);
|
|
|
|
Database::connect(connection_string).await.unwrap()
|
2024-11-26 22:30:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn is_alive() -> bool {
|
|
|
|
tokio::select! {
|
2024-12-02 23:56:43 +03:00
|
|
|
|
|
|
|
_ = sleep(Duration::from_secs(1)) => false,
|
2024-11-26 22:30:25 +03:00
|
|
|
}
|
|
|
|
}
|