users: get user by id, email, username

This commit is contained in:
Philippe Loctaux 2023-03-11 00:33:58 +01:00
parent b8f6cae85e
commit d790d2ff29
8 changed files with 254 additions and 6 deletions

View file

@ -51,4 +51,24 @@ impl Users {
.await
.map_err(handle_error)
}
pub async fn get_one_by_email(
conn: impl SqliteExecutor<'_>,
email: &str,
) -> Result<Option<Self>, Error> {
sqlx::query_file_as!(Self, "queries/users/get_one_by_email.sql", email)
.fetch_optional(conn)
.await
.map_err(handle_error)
}
pub async fn get_one_by_username(
conn: impl SqliteExecutor<'_>,
username: &str,
) -> Result<Option<Self>, Error> {
sqlx::query_file_as!(Self, "queries/users/get_one_by_username.sql", username)
.fetch_optional(conn)
.await
.map_err(handle_error)
}
}