From 7b30c08f5f7ef67f9874211d1ac6258c8f8488cd Mon Sep 17 00:00:00 2001 From: realaravinth Date: Sat, 4 Jun 2022 20:58:05 +0530 Subject: [PATCH] feat: impl interface to get user data sqlx sqlite --- db/db-sqlx-sqlite/sqlx-data.json | 24 ++++++++++++++++++++++++ db/db-sqlx-sqlite/src/lib.rs | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/db/db-sqlx-sqlite/sqlx-data.json b/db/db-sqlx-sqlite/sqlx-data.json index 70ce312..76a09ad 100644 --- a/db/db-sqlx-sqlite/sqlx-data.json +++ b/db/db-sqlx-sqlite/sqlx-data.json @@ -339,5 +339,29 @@ } }, "query": "DELETE FROM starchart_forges WHERE hostname = ($1)" + }, + "fbf6dd6bc2bc6121e080903fc9d6d9031b177acacf64fa92b7b52bd79f8fe89c": { + "describe": { + "columns": [ + { + "name": "html_url", + "ordinal": 0, + "type_info": "Text" + }, + { + "name": "profile_photo_html_url", + "ordinal": 1, + "type_info": "Text" + } + ], + "nullable": [ + false, + true + ], + "parameters": { + "Right": 2 + } + }, + "query": "SELECT html_url, profile_photo_html_url FROM starchart_users WHERE username = $1 AND \n hostname_id = (SELECT ID FROM starchart_forges WHERE hostname = $2)" } } \ No newline at end of file diff --git a/db/db-sqlx-sqlite/src/lib.rs b/db/db-sqlx-sqlite/src/lib.rs index 4bf3249..0460d03 100644 --- a/db/db-sqlx-sqlite/src/lib.rs +++ b/db/db-sqlx-sqlite/src/lib.rs @@ -234,6 +234,30 @@ impl SCDatabase for Database { Ok(()) } + /// get user data + async fn get_user(&self, username: &str, hostname: &str) -> DBResult { + struct InnerUser { + profile_photo_html_url: Option, + html_url: String, + } + let res = sqlx::query_as!( + InnerUser, + "SELECT html_url, profile_photo_html_url FROM starchart_users WHERE username = $1 AND + hostname_id = (SELECT ID FROM starchart_forges WHERE hostname = $2)", + username, + hostname, + ) + .fetch_one(&self.pool) + .await + .map_err(|e| DBError::DBError(Box::new(e)))?; + Ok(User { + username: username.into(), + hostname: hostname.into(), + profile_photo: res.profile_photo_html_url, + html_link: res.html_url, + }) + } + /// check if an user exists. When hostname of a forge instace is provided, username search is /// done only on that forge async fn user_exists(&self, username: &str, hostname: Option<&str>) -> DBResult {