From 9e5d6c9bdd83af026ac24001f3444b9318783ef3 Mon Sep 17 00:00:00 2001 From: trivernis Date: Fri, 1 Oct 2021 20:39:24 +0200 Subject: [PATCH] Restructure database crate Signed-off-by: trivernis --- .../mediarepo-database/src/database.rs | 20 ------------------- .../mediarepo-database/src/lib.rs | 9 ++++++--- 2 files changed, 6 insertions(+), 23 deletions(-) delete mode 100644 mediarepo-daemon/mediarepo-database/src/database.rs diff --git a/mediarepo-daemon/mediarepo-database/src/database.rs b/mediarepo-daemon/mediarepo-database/src/database.rs deleted file mode 100644 index 43c4ab8..0000000 --- a/mediarepo-daemon/mediarepo-database/src/database.rs +++ /dev/null @@ -1,20 +0,0 @@ -use sea_orm::{DatabaseConnection, Database}; -use mediarepo_core::error::{RepoDatabaseResult}; - -pub struct RepoDatabase { - connection: DatabaseConnection, -} - -impl RepoDatabase { - /// Creates a new repo database from an existing connection - pub(crate) fn new(connection: DatabaseConnection) -> Self { - Self {connection} - } - - /// Creates a new Repo Database Connection - pub(crate) async fn connect>(uri: S) -> RepoDatabaseResult { - let connection = Database::connect(uri.as_ref()).await?; - - Ok(Self::new(connection)) - } -} \ No newline at end of file diff --git a/mediarepo-daemon/mediarepo-database/src/lib.rs b/mediarepo-daemon/mediarepo-database/src/lib.rs index cbb6969..60f2078 100644 --- a/mediarepo-daemon/mediarepo-database/src/lib.rs +++ b/mediarepo-daemon/mediarepo-database/src/lib.rs @@ -1,13 +1,16 @@ use mediarepo_core::error::{RepoDatabaseResult}; use crate::database::RepoDatabase; +use sea_orm::{DatabaseConnection, Database}; + -pub mod database; pub mod entities; /// Connects to the database, runs migrations and returns the RepoDatabase wrapper type -pub async fn get_database>(uri: S) -> RepoDatabaseResult { +pub async fn get_database>(uri: S) -> RepoDatabaseResult { migrate(uri.as_ref()).await?; - RepoDatabase::connect(uri).await + let conn = Database::connect(uri).await?; + + Ok(conn) } async fn migrate(uri: &str) -> RepoDatabaseResult<()> {