From 2055a00565bc5b9243c901d603c8392fda484437 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Sun, 1 May 2022 19:08:01 +0530 Subject: [PATCH] feat: sqlite sqlx implementation for repository_exists --- db/db-sqlx-sqlite/sqlx-data.json | 18 ++++++++++++++++++ db/db-sqlx-sqlite/src/lib.rs | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/db/db-sqlx-sqlite/sqlx-data.json b/db/db-sqlx-sqlite/sqlx-data.json index 922d4cc..e45514e 100644 --- a/db/db-sqlx-sqlite/sqlx-data.json +++ b/db/db-sqlx-sqlite/sqlx-data.json @@ -54,6 +54,24 @@ }, "query": "SELECT ID FROM starchart_forge_type WHERE name = $1" }, + "71079442588dfaece04582acdb14d2c8928c695d4eab5332d09b82cefc880d54": { + "describe": { + "columns": [ + { + "name": "ID", + "ordinal": 0, + "type_info": "Int64" + } + ], + "nullable": [ + false + ], + "parameters": { + "Right": 3 + } + }, + "query": "SELECT ID FROM starchart_repositories\n WHERE \n name = $1\n AND\n owner_id = ( SELECT ID FROM starchart_users WHERE username = $2)\n AND\n hostname_id = (SELECT ID FROM starchart_forges WHERE hostname = $3)" + }, "8c78e074d78291f9d3c4ef3526bae00cb356591edad79a7fb1f20aa7bb681216": { "describe": { "columns": [], diff --git a/db/db-sqlx-sqlite/src/lib.rs b/db/db-sqlx-sqlite/src/lib.rs index 947cf9f..ff8a4f8 100644 --- a/db/db-sqlx-sqlite/src/lib.rs +++ b/db/db-sqlx-sqlite/src/lib.rs @@ -218,6 +218,29 @@ impl SCDatabase for Database { }, } } + + /// check if a repo exists. + async fn repository_exists(&self, name: &str, owner: &str, hostname: &str) -> DBResult { + match sqlx::query!( + "SELECT ID FROM starchart_repositories + WHERE + name = $1 + AND + owner_id = ( SELECT ID FROM starchart_users WHERE username = $2) + AND + hostname_id = (SELECT ID FROM starchart_forges WHERE hostname = $3)", + name, + owner, + hostname, + ) + .fetch_one(&self.pool) + .await + { + Ok(_) => Ok(true), + Err(Error::RowNotFound) => Ok(false), + Err(e) => Err(DBError::DBError(Box::new(e).into())), + } + } } fn now_unix_time_stamp() -> i64 {