From 717ab0677b37f55b95b14d8416a65dae4dadc235 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 30 Dec 2020 15:55:35 +0000 Subject: [PATCH] Convert load user queries to compile-checked --- src/db.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/db.rs b/src/db.rs index d511551..752d144 100644 --- a/src/db.rs +++ b/src/db.rs @@ -35,17 +35,23 @@ pub(crate) trait Dao { #[rocket::async_trait] impl Dao for SqlitePool { async fn load_user_by_id(&self, user_id: i32) -> sqlx::Result> { - sqlx::query_as::<_, User>("SELECT * FROM users WHERE id = ?") - .bind(user_id) - .fetch_optional(self) - .await + sqlx::query_as!( + User, + r#"SELECT id as "id: _", username, password FROM users WHERE id = ?"#, + user_id + ) + .fetch_optional(self) + .await } async fn load_user(&self, for_username: &str) -> sqlx::Result> { - sqlx::query_as::<_, User>("SELECT * FROM users WHERE username = ?") - .bind(for_username) - .fetch_optional(self) - .await + sqlx::query_as!( + User, + r#"SELECT id as "id: _", username, password FROM users WHERE username = ?"#, + for_username + ) + .fetch_optional(self) + .await } async fn insert_user(&self, new_user: NewUser<'_>) -> sqlx::Result {