12 lines
398 B
Rust
12 lines
398 B
Rust
|
use migration::{Migrator, MigratorTrait};
|
||
|
use sea_orm::{Database, DatabaseConnection, DbErr};
|
||
|
use std::env;
|
||
|
|
||
|
pub async fn get_connection() -> Result<DatabaseConnection, DbErr> {
|
||
|
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
||
|
|
||
|
let db_connection = Database::connect(database_url).await?;
|
||
|
Migrator::up(&db_connection, None).await?;
|
||
|
Ok(db_connection)
|
||
|
}
|