From 1aec44d4e70ec5b2c6f9a15534d9557283d3fe90 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Tue, 7 May 2024 16:27:06 +0200 Subject: [PATCH] Fix query --- crates/lavina-core/src/repo/room.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/crates/lavina-core/src/repo/room.rs b/crates/lavina-core/src/repo/room.rs index 77104fe..4316f7c 100644 --- a/crates/lavina-core/src/repo/room.rs +++ b/crates/lavina-core/src/repo/room.rs @@ -6,24 +6,21 @@ use crate::repo::Storage; impl Storage { pub async fn is_room_member(&self, room_id: u32, player_id: u32) -> Result { let mut executor = self.conn.lock().await; - let res: (bool,) = sqlx::query_as( + let res: (u32,) = sqlx::query_as( " - select - exists ( - select - count(*) - from - memberships - where - user_id = ? and room_id = ? - ); + select + count(*) + from + memberships + where + user_id = ? and room_id = ?; ", ) .bind(player_id) .bind(room_id) .fetch_one(&mut *executor) .await?; - Ok(res.0) + Ok(res.0 > 0) } pub async fn add_room_member(&self, room_id: u32, player_id: u32) -> Result<()> { let mut executor = self.conn.lock().await;