forked from lavina/lavina
Fix query
This commit is contained in:
parent
53adc93d25
commit
1aec44d4e7
|
@ -6,24 +6,21 @@ use crate::repo::Storage;
|
||||||
impl Storage {
|
impl Storage {
|
||||||
pub async fn is_room_member(&self, room_id: u32, player_id: u32) -> Result<bool> {
|
pub async fn is_room_member(&self, room_id: u32, player_id: u32) -> Result<bool> {
|
||||||
let mut executor = self.conn.lock().await;
|
let mut executor = self.conn.lock().await;
|
||||||
let res: (bool,) = sqlx::query_as(
|
let res: (u32,) = sqlx::query_as(
|
||||||
"
|
"
|
||||||
select
|
|
||||||
exists (
|
|
||||||
select
|
select
|
||||||
count(*)
|
count(*)
|
||||||
from
|
from
|
||||||
memberships
|
memberships
|
||||||
where
|
where
|
||||||
user_id = ? and room_id = ?
|
user_id = ? and room_id = ?;
|
||||||
);
|
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.bind(player_id)
|
.bind(player_id)
|
||||||
.bind(room_id)
|
.bind(room_id)
|
||||||
.fetch_one(&mut *executor)
|
.fetch_one(&mut *executor)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(res.0)
|
Ok(res.0 > 0)
|
||||||
}
|
}
|
||||||
pub async fn add_room_member(&self, room_id: u32, player_id: u32) -> Result<()> {
|
pub async fn add_room_member(&self, room_id: u32, player_id: u32) -> Result<()> {
|
||||||
let mut executor = self.conn.lock().await;
|
let mut executor = self.conn.lock().await;
|
||||||
|
|
Loading…
Reference in New Issue