Skip to content

Commit a04b0fc

Browse files
committed
database-storage: use query_scalar in some cases
1 parent 5dabd1c commit a04b0fc

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Diff for: src/storage/database.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,33 @@ impl DatabaseBackend {
1717
}
1818

1919
pub(super) async fn exists(&self, path: &str) -> Result<bool> {
20-
Ok(sqlx::query!(
20+
Ok(sqlx::query_scalar!(
2121
r#"SELECT COUNT(*) > 0 as "has_count!" FROM files WHERE path = $1"#,
2222
path
2323
)
2424
.fetch_one(&self.pool)
25-
.await?
26-
.has_count)
25+
.await?)
2726
}
2827

2928
pub(super) async fn get_public_access(&self, path: &str) -> Result<bool> {
30-
match sqlx::query!(
31-
"SELECT public
32-
FROM files
29+
match sqlx::query_scalar!(
30+
"SELECT public
31+
FROM files
3332
WHERE path = $1",
3433
path
3534
)
3635
.fetch_optional(&self.pool)
3736
.await?
3837
{
39-
Some(row) => Ok(row.public),
38+
Some(public) => Ok(public),
4039
None => Err(super::PathNotFoundError.into()),
4140
}
4241
}
4342

4443
pub(super) async fn set_public_access(&self, path: &str, public: bool) -> Result<()> {
4544
if sqlx::query!(
46-
"UPDATE files
47-
SET public = $2
45+
"UPDATE files
46+
SET public = $2
4847
WHERE path = $1",
4948
path,
5049
public,

0 commit comments

Comments
 (0)