From 846ccfd1e8c8628d97bc4e18a283ef52f63e52f4 Mon Sep 17 00:00:00 2001 From: crowlkats Date: Wed, 28 Feb 2024 15:46:25 +0100 Subject: [PATCH] re-add query --- api/src/db/database.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/api/src/db/database.rs b/api/src/db/database.rs index 0b296ee4..cd6ba1a3 100644 --- a/api/src/db/database.rs +++ b/api/src/db/database.rs @@ -86,6 +86,24 @@ impl Database { .await } + #[instrument(name = "Database::get_user_by_email", skip(self), err)] + pub async fn get_user_by_email( + &self, + email: &str, + ) -> Result> { + sqlx::query_as!( + User, + r#"SELECT id, name, email, avatar_url, updated_at, created_at, github_id, is_blocked, is_staff, scope_limit, waitlist_accepted_at, + (SELECT COUNT(created_at) FROM scope_invites WHERE target_user_id = id) as "invite_count!", + (SELECT COUNT(created_at) FROM scopes WHERE creator = id) as "scope_usage!" + FROM users + WHERE email = $1"#, + email + ) + .fetch_optional(&self.pool) + .await + } + #[instrument(name = "Database::list_users", skip(self), err)] pub async fn list_users( &self,