From 3739ed993c84da8b198d6773c2a24374b5e16e20 Mon Sep 17 00:00:00 2001 From: ThePerkinrex Date: Tue, 17 Nov 2020 22:38:42 +0100 Subject: [PATCH] Fix compile time issues --- server/src/db.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/server/src/db.rs b/server/src/db.rs index 17e9c00..62cb550 100644 --- a/server/src/db.rs +++ b/server/src/db.rs @@ -1,5 +1,5 @@ use sqlx::{ - pool::PoolConnection, prelude::*, query_as, query_file_unchecked, query_unchecked, FromRow, + pool::PoolConnection, prelude::*, query_as, query_file_unchecked, query, FromRow, SqliteConnection, SqlitePool, }; // use tokio::stream::StreamExt; @@ -41,7 +41,7 @@ pub struct DbConnection { } use uuid::Uuid; -type LobbyId = (i32,); +// type LobbyId = (i32,); // FIXME: return Results intead of crashing impl DbConnection { fn new(conn: PoolConnection) -> Self { @@ -52,9 +52,9 @@ impl DbConnection { let uuid = Uuid::new_v4(); // println!("{:?}", uuid.as_bytes().to_vec()); self.conn - .execute(query_unchecked!( - "INSERT INTO Users(uuid, name) VALUES(?, ?)", - uuid.as_bytes().to_vec(), + .execute(query( + "INSERT INTO Users(uuid, name) VALUES(?, ?)").bind( + uuid.as_bytes().to_vec()).bind( name.to_string() )) .await @@ -81,9 +81,9 @@ impl DbConnection { log::info!("Created the lobby {}", id); self.conn - .execute(query_unchecked!( - "INSERT INTO Lobbies(id, public) VALUES(?, ?)", - id as i32, + .execute(query( + "INSERT INTO Lobbies(id, public) VALUES(?, ?)").bind( + id as i32).bind( public )) .await @@ -94,9 +94,9 @@ impl DbConnection { pub async fn join_lobby(&mut self, user: Uuid, lobby: u32) { log::info!("{} joined the lobby {}", user, lobby); self.conn - .execute(query_unchecked!( - "INSERT INTO UsersInLobbies(UserId, LobbyId) VALUES(?, ?)", - user.as_bytes().to_vec(), + .execute(query( + "INSERT INTO UsersInLobbies(UserId, LobbyId) VALUES(?, ?)").bind( + user.as_bytes().to_vec()).bind( lobby as i32 )) .await @@ -108,14 +108,14 @@ impl DbConnection { let v = query_as::<_, (i32,)>("SELECT LobbyId FROM UsersInLobbies WHERE UserId = ?").bind(user.as_bytes().to_vec()).fetch_one(&mut self.conn).await; self.conn - .execute(query_unchecked!( - "DELETE FROM UsersInLobbies WHERE UserId = ?", + .execute(query( + "DELETE FROM UsersInLobbies WHERE UserId = ?").bind( user.as_bytes().to_vec(), )) .await .unwrap(); if let Ok((id, )) = v { - let lines = self.conn.execute(query_unchecked!("DELETE FROM Lobbies WHERE 0 = (SELECT count(*) FROM UsersInLobbies WHERE LobbyID = ?)", id)).await.unwrap(); + let lines = self.conn.execute(query("DELETE FROM Lobbies WHERE 0 = (SELECT count(*) FROM UsersInLobbies WHERE LobbyID = ?)").bind( id)).await.unwrap(); log::info!("Deleted {} lobbies ({})", lines, id as u32) } } @@ -123,13 +123,13 @@ impl DbConnection { pub async fn disconnect(&mut self, user: &Uuid) { log::info!("{} disconnecting", user); self.conn - .execute(query_unchecked!( - "DELETE FROM UsersInLobbies WHERE UserId = ?", + .execute(query( + "DELETE FROM UsersInLobbies WHERE UserId = ?").bind( user.as_bytes().to_vec(), )); self.conn - .execute(query_unchecked!( - "DELETE FROM Users WHERE UUID = ?", + .execute(query( + "DELETE FROM Users WHERE UUID = ?").bind( user.as_bytes().to_vec(), )) .await