summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2024-08-13 21:33:36 -0400
committerpommicket <pommicket@gmail.com>2024-08-13 22:10:18 -0400
commit56c6670c66ff7db2e30378b098102578e75f98fb (patch)
treed3d4318e1be79c9d3a5695daa93d04dcfed7ec8c
parentbc34326b935d8d460c3a14951237a744d12d7de3 (diff)
start puzl
-rw-r--r--server/Cargo.lock7
-rw-r--r--server/Cargo.toml2
-rw-r--r--server/src/main.rs13
3 files changed, 20 insertions, 2 deletions
diff --git a/server/Cargo.lock b/server/Cargo.lock
index ee52661..4cb5a9c 100644
--- a/server/Cargo.lock
+++ b/server/Cargo.lock
@@ -18,6 +18,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
+name = "array-init"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc"
+
+[[package]]
name = "async-trait"
version = "0.1.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -452,6 +458,7 @@ version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02048d9e032fb3cc3413bbf7b83a15d84a5d419778e2628751896d856498eee9"
dependencies = [
+ "array-init",
"bytes",
"fallible-iterator",
"postgres-protocol",
diff --git a/server/Cargo.toml b/server/Cargo.toml
index 642bbe1..8a848e9 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -7,7 +7,7 @@ edition = "2021"
futures-util = "0.3"
rand = { version = "0.8.5", features = ["std", "std_rng"] }
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread", "net", "io-util", "sync", "time", "process"] }
-tokio-postgres = "0.7.11"
+tokio-postgres = { version = "0.7.11", features = ["array-impls"] }
tokio-tungstenite = "0.23.1"
tungstenite = "0.23.0"
zerocopy = "0.7.35"
diff --git a/server/src/main.rs b/server/src/main.rs
index eb9674b..1ec62a6 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -35,7 +35,18 @@ struct Server {
impl Server {
async fn create_table_if_not_exists(&self) -> Result<()> {
- todo!()
+ if self.database.query("SELECT FROM puzzles", &[]).await.is_ok() {
+ return Ok(());
+ } else {
+ self.database.execute("CREATE TABLE puzzles (
+ id char($1) PRIMARY KEY,
+ url varchar(256),
+ create_time timestamp,
+ connectivity int2[],
+ positions float4[]
+ )", &[&(PUZZLE_ID_LEN as i32)]).await?;
+ return Ok(());
+ }
}
async fn try_register_id(&self, id: [u8; PUZZLE_ID_LEN]) -> Result<bool> {
todo!()