Browse Source

Fix compile time issues

new_protocol
ThePerkinrex 5 years ago
parent
commit
3739ed993c
No known key found for this signature in database GPG Key ID: 1F45A7C4BFB41607
  1. 36
      server/src/db.rs

36
server/src/db.rs

@ -1,5 +1,5 @@
use sqlx::{ 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, SqliteConnection, SqlitePool,
}; };
// use tokio::stream::StreamExt; // use tokio::stream::StreamExt;
@ -41,7 +41,7 @@ pub struct DbConnection {
} }
use uuid::Uuid; use uuid::Uuid;
type LobbyId = (i32,); // type LobbyId = (i32,);
// FIXME: return Results intead of crashing // FIXME: return Results intead of crashing
impl DbConnection { impl DbConnection {
fn new(conn: PoolConnection<SqliteConnection>) -> Self { fn new(conn: PoolConnection<SqliteConnection>) -> Self {
@ -52,9 +52,9 @@ impl DbConnection {
let uuid = Uuid::new_v4(); let uuid = Uuid::new_v4();
// println!("{:?}", uuid.as_bytes().to_vec()); // println!("{:?}", uuid.as_bytes().to_vec());
self.conn self.conn
.execute(query_unchecked!( .execute(query(
"INSERT INTO Users(uuid, name) VALUES(?, ?)", "INSERT INTO Users(uuid, name) VALUES(?, ?)").bind(
uuid.as_bytes().to_vec(), uuid.as_bytes().to_vec()).bind(
name.to_string() name.to_string()
)) ))
.await .await
@ -81,9 +81,9 @@ impl DbConnection {
log::info!("Created the lobby {}", id); log::info!("Created the lobby {}", id);
self.conn self.conn
.execute(query_unchecked!( .execute(query(
"INSERT INTO Lobbies(id, public) VALUES(?, ?)", "INSERT INTO Lobbies(id, public) VALUES(?, ?)").bind(
id as i32, id as i32).bind(
public public
)) ))
.await .await
@ -94,9 +94,9 @@ impl DbConnection {
pub async fn join_lobby(&mut self, user: Uuid, lobby: u32) { pub async fn join_lobby(&mut self, user: Uuid, lobby: u32) {
log::info!("{} joined the lobby {}", user, lobby); log::info!("{} joined the lobby {}", user, lobby);
self.conn self.conn
.execute(query_unchecked!( .execute(query(
"INSERT INTO UsersInLobbies(UserId, LobbyId) VALUES(?, ?)", "INSERT INTO UsersInLobbies(UserId, LobbyId) VALUES(?, ?)").bind(
user.as_bytes().to_vec(), user.as_bytes().to_vec()).bind(
lobby as i32 lobby as i32
)) ))
.await .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; 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 self.conn
.execute(query_unchecked!( .execute(query(
"DELETE FROM UsersInLobbies WHERE UserId = ?", "DELETE FROM UsersInLobbies WHERE UserId = ?").bind(
user.as_bytes().to_vec(), user.as_bytes().to_vec(),
)) ))
.await .await
.unwrap(); .unwrap();
if let Ok((id, )) = v { 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) log::info!("Deleted {} lobbies ({})", lines, id as u32)
} }
} }
@ -123,13 +123,13 @@ impl DbConnection {
pub async fn disconnect(&mut self, user: &Uuid) { pub async fn disconnect(&mut self, user: &Uuid) {
log::info!("{} disconnecting", user); log::info!("{} disconnecting", user);
self.conn self.conn
.execute(query_unchecked!( .execute(query(
"DELETE FROM UsersInLobbies WHERE UserId = ?", "DELETE FROM UsersInLobbies WHERE UserId = ?").bind(
user.as_bytes().to_vec(), user.as_bytes().to_vec(),
)); ));
self.conn self.conn
.execute(query_unchecked!( .execute(query(
"DELETE FROM Users WHERE UUID = ?", "DELETE FROM Users WHERE UUID = ?").bind(
user.as_bytes().to_vec(), user.as_bytes().to_vec(),
)) ))
.await .await

Loading…
Cancel
Save