flix_db/connection.rs
1//! Types and functions related to [DatabaseConnection]s
2
3use sea_orm::{DatabaseConnection, DbErr};
4use sea_orm_migration::MigratorTrait as _;
5
6/// A newtype wrapping a [DatabaseConnection]
7pub struct Connection(DatabaseConnection);
8
9impl Connection {
10 /// Helper function for applying database migrations while wrapping a
11 /// [DatabaseConnection] in a newtype
12 pub async fn try_from(database: DatabaseConnection) -> Result<Self, DbErr> {
13 crate::migration::Migrator::up(&database, None).await?;
14 Ok(Self(database))
15 }
16}
17
18impl AsRef<DatabaseConnection> for Connection {
19 fn as_ref(&self) -> &DatabaseConnection {
20 &self.0
21 }
22}