Skip to content

Commit

Permalink
re-add query
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Feb 28, 2024
1 parent a53c834 commit 846ccfd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/src/db/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<User>> {
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,
Expand Down

0 comments on commit 846ccfd

Please sign in to comment.