feat: impl interface to get user data sqlx sqlite

This commit is contained in:
Aravinth Manivannan 2022-06-04 20:58:05 +05:30
parent 653088376a
commit 7b30c08f5f
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
2 changed files with 48 additions and 0 deletions

View file

@ -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)"
}
}

View file

@ -234,6 +234,30 @@ impl SCDatabase for Database {
Ok(())
}
/// get user data
async fn get_user(&self, username: &str, hostname: &str) -> DBResult<User> {
struct InnerUser {
profile_photo_html_url: Option<String>,
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<bool> {