Convert character db methods to compile-checked queries
This commit is contained in:
parent
5ea07b8953
commit
53501c3747
2
.env
2
.env
|
@ -1 +1 @@
|
|||
DATABASE_URL="./tenebrous.sqlite"
|
||||
DATABASE_URL="sqlite://./tenebrous.sqlite"
|
||||
|
|
26
src/db.rs
26
src/db.rs
|
@ -69,22 +69,32 @@ impl Dao for SqlitePool {
|
|||
}
|
||||
|
||||
async fn load_character_list(&self, for_user_id: i32) -> Result<Vec<StrippedCharacter>, Error> {
|
||||
sqlx::query_as::<_, StrippedCharacter>(
|
||||
"SELECT id, user_id, viewable, character_name, data_type, data_version
|
||||
FROM characters WHERE user_id = ?",
|
||||
sqlx::query_as!(
|
||||
StrippedCharacter,
|
||||
r#"SELECT id as "id: _",
|
||||
user_id as "user_id: _",
|
||||
data_type as "data_type: _",
|
||||
data_version as "data_version: _",
|
||||
viewable, character_name
|
||||
FROM characters WHERE user_id = ?"#,
|
||||
for_user_id
|
||||
)
|
||||
.bind(for_user_id)
|
||||
.fetch_all(self)
|
||||
.await
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
async fn load_character(&self, character_id: i32) -> Result<Option<Character>, Error> {
|
||||
sqlx::query_as::<_, Character>(
|
||||
"SELECT id, user_id, viewable, character_name, data_type, data_version, data
|
||||
FROM characters WHERE id = ?",
|
||||
sqlx::query_as!(
|
||||
Character,
|
||||
r#"SELECT id as "id: _",
|
||||
user_id as "user_id: _",
|
||||
viewable, character_name, data,
|
||||
data_type as "data_type: _",
|
||||
data_version as "data_version: _"
|
||||
FROM characters WHERE id = ?"#,
|
||||
character_id
|
||||
)
|
||||
.bind(character_id)
|
||||
.fetch_optional(self)
|
||||
.await
|
||||
.map_err(|e| e.into())
|
||||
|
|
Loading…
Reference in New Issue