Convert load user queries to compile-checked

This commit is contained in:
jeff 2020-12-30 15:55:35 +00:00
parent ed9b7c1a81
commit 717ab0677b
1 changed files with 14 additions and 8 deletions

View File

@ -35,15 +35,21 @@ pub(crate) trait Dao {
#[rocket::async_trait] #[rocket::async_trait]
impl Dao for SqlitePool { impl Dao for SqlitePool {
async fn load_user_by_id(&self, user_id: i32) -> sqlx::Result<Option<User>> { async fn load_user_by_id(&self, user_id: i32) -> sqlx::Result<Option<User>> {
sqlx::query_as::<_, User>("SELECT * FROM users WHERE id = ?") sqlx::query_as!(
.bind(user_id) User,
r#"SELECT id as "id: _", username, password FROM users WHERE id = ?"#,
user_id
)
.fetch_optional(self) .fetch_optional(self)
.await .await
} }
async fn load_user(&self, for_username: &str) -> sqlx::Result<Option<User>> { async fn load_user(&self, for_username: &str) -> sqlx::Result<Option<User>> {
sqlx::query_as::<_, User>("SELECT * FROM users WHERE username = ?") sqlx::query_as!(
.bind(for_username) User,
r#"SELECT id as "id: _", username, password FROM users WHERE username = ?"#,
for_username
)
.fetch_optional(self) .fetch_optional(self)
.await .await
} }