feat: fixup "setup seaorm and a first "debug" entity as example"
This commit is contained in:
11
crates/backend/src/db.rs
Normal file
11
crates/backend/src/db.rs
Normal file
@ -0,0 +1,11 @@
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user