init
This commit is contained in:
15
backend/src/db.rs
Normal file
15
backend/src/db.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use sea_orm::{ConnectOptions, Database, DatabaseConnection};
|
||||
use std::time::Duration;
|
||||
|
||||
pub type Db = DatabaseConnection;
|
||||
|
||||
pub async fn init_db() -> anyhow::Result<Db> {
|
||||
let mut opt = ConnectOptions::new(std::env::var("DB_URL")?);
|
||||
opt.max_connections(20)
|
||||
.min_connections(5)
|
||||
.connect_timeout(Duration::from_secs(8))
|
||||
.idle_timeout(Duration::from_secs(600))
|
||||
.sqlx_logging(false);
|
||||
let conn = Database::connect(opt).await?;
|
||||
Ok(conn)
|
||||
}
|
||||
Reference in New Issue
Block a user