diff --git a/backend/database/src/states.rs b/backend/database/src/states.rs index 0d73434..f521b1c 100644 --- a/backend/database/src/states.rs +++ b/backend/database/src/states.rs @@ -16,6 +16,12 @@ 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)] @@ -59,10 +65,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()) @@ -72,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.pool = sqlx::SqlitePool::connect(&url).await?; Ok(self) } @@ -101,7 +107,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 @@ -114,9 +120,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) } @@ -143,7 +149,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?;