From f8876800ebf61adce66ea42e4953b6787fbbfdac Mon Sep 17 00:00:00 2001 From: Murthadza Aznam <61819672+Thaza-Kun@users.noreply.github.com> Date: Mon, 15 Jul 2024 00:07:44 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=F0=9F=90=9B=20Borrow=20connection,?= =?UTF-8?q?=20not=20consume"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/database/src/states.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/backend/database/src/states.rs b/backend/database/src/states.rs index f521b1c..0d73434 100644 --- a/backend/database/src/states.rs +++ b/backend/database/src/states.rs @@ -16,12 +16,6 @@ pub struct Connection { pub pool: sqlx::Pool, } -impl From> for Connection { - fn from(value: sqlx::Pool) -> Self { - Self { pool: value } - } -} - /// Counts of selected items. #[allow(missing_docs)] #[derive(Debug, Clone, Default, serde::Serialize, PartialEq, ts_rs::TS)] @@ -65,10 +59,10 @@ impl Connection { /// ```sql #[doc = include_str!("../transactions/postgres/count_items.sql")] /// ``` - pub async fn statistics(&self) -> Result> { + pub async fn statistics(self) -> Result> { let inter: Counts> = sqlx::query_file_as!(Counts, "transactions/postgres/count_items.sql") - .fetch_one(self.pool) + .fetch_one(&self.pool) .await .map_err(BackendError::from)?; Ok(inter.unwrap_fields()) @@ -78,7 +72,7 @@ impl Connection { #[cfg(feature = "sqlite")] impl Connection { /// Forcefully reconnect to the specified url. - pub async fn renew(&mut self, url: String) -> Result { + pub async fn renew(mut self, url: String) -> Result { self.pool = sqlx::SqlitePool::connect(&url).await?; Ok(self) } @@ -107,7 +101,7 @@ impl Connection { /// ```sql #[doc = include_str!("../transactions/sqlite/count_items.sql")] /// ``` - pub async fn statistics(&self) -> Result> { + pub async fn statistics(self) -> Result> { sqlx::query_file_as!(Counts, "transactions/sqlite/count_items.sql") .fetch_one(&self.pool) .await @@ -120,9 +114,9 @@ impl Connection { /// ```sql /// SELECT nama AS item FROM golongan_kata /// ``` - pub async fn get_golongan_kata_enumeration(&self) -> Result> { + pub async fn get_golongan_kata_enumeration(self) -> Result> { sqlx::query_as!(StringItem, "SELECT nama AS item FROM golongan_kata") - .fetch_all(self.pool) + .fetch_all(&self.pool) .await .map_err(BackendError::from) } @@ -149,7 +143,7 @@ impl Connection { /// ```sql #[doc = include_str!("../presets/golongan_kata_ms-my.sql")] /// ``` - pub async fn populate_with_presets(&self) -> Result { + pub async fn populate_with_presets(self) -> Result { sqlx::query_file!("presets/golongan_kata_ms-my.sql") .execute(&self.pool) .await?;