Convert load user queries to compile-checked
This commit is contained in:
parent
ed9b7c1a81
commit
717ab0677b
14
src/db.rs
14
src/db.rs
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue