From 72792f85c5e19253fbb04b841fba60823991a1a3 Mon Sep 17 00:00:00 2001 From: Thaza_Kun <61819672+Thaza-Kun@users.noreply.github.com> Date: Mon, 15 Jul 2024 00:07:20 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20compilation=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/database/src/states.rs | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/backend/database/src/states.rs b/backend/database/src/states.rs index f521b1c..3aada23 100644 --- a/backend/database/src/states.rs +++ b/backend/database/src/states.rs @@ -16,11 +16,11 @@ pub struct Connection { pub pool: sqlx::Pool, } -impl From> for Connection { - fn from(value: sqlx::Pool) -> Self { - Self { pool: value } - } -} +// impl From> for Connection { +// fn from(value: sqlx::Pool) -> Self { +// Self { pool: value } +// } +// } /// Counts of selected items. #[allow(missing_docs)] @@ -68,7 +68,7 @@ impl Connection { 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 +78,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> { self.pool = sqlx::SqlitePool::connect(&url).await?; Ok(self) } @@ -92,12 +92,15 @@ impl Connection { // Automatically migrate to current version Self { pool } } - Err(_) => dbg!(Self::create_and_migrate(url) - .await - .unwrap() - .populate_with_presets() - .await - .unwrap()), + Err(_) => { + let _ = Self::create_and_migrate(url.clone()) + .await + .unwrap() + .populate_with_presets() + .await + .unwrap(); + Connection::from(url).await + } } } @@ -122,7 +125,7 @@ impl Connection { /// ``` 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 +152,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<&Self> { sqlx::query_file!("presets/golongan_kata_ms-my.sql") .execute(&self.pool) .await?;