Convert load user queries to compile-checked
This commit is contained in:
parent
fb1c21d710
commit
e148b45edd
14
src/db.rs
14
src/db.rs
|
@ -35,15 +35,21 @@ pub(crate) trait Dao {
|
|||
#[rocket::async_trait]
|
||||
impl Dao for SqlitePool {
|
||||
async fn load_user_by_id(&self, user_id: i32) -> sqlx::Result<Option<User>> {
|
||||
sqlx::query_as::<_, User>("SELECT * FROM users WHERE id = ?")
|
||||
.bind(user_id)
|
||||
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<Option<User>> {
|
||||
sqlx::query_as::<_, User>("SELECT * FROM users WHERE username = ?")
|
||||
.bind(for_username)
|
||||
sqlx::query_as!(
|
||||
User,
|
||||
r#"SELECT id as "id: _", username, password FROM users WHERE username = ?"#,
|
||||
for_username
|
||||
)
|
||||
.fetch_optional(self)
|
||||
.await
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue