From 2ebf8ab55e9c66d078040863530da892fb27c3ed Mon Sep 17 00:00:00 2001 From: Gandalf Date: Tue, 13 Jun 2023 15:54:47 +0200 Subject: [PATCH] dismiss manual sql code, seek an ORM instead --- Cargo.toml | 5 ++-- db.sql | 85 ------------------------------------------------------ src/db.sql | 7 ----- 3 files changed, 3 insertions(+), 94 deletions(-) delete mode 100644 db.sql delete mode 100644 src/db.sql diff --git a/Cargo.toml b/Cargo.toml index 48f62ae..8cff07f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,8 @@ edition = "2018" [dependencies] tokio = { version = "0.2", features = ["macros"] } warp = "0.2" -mobc-postgres = { version = "0.5", features = ["with-chrono-0_4"] } -mobc = "0.5" +sqlx = +ormx = serde = {version = "1.0", features = ["derive"] } serde_derive = "1.0" serde_json = "1.0" @@ -24,3 +24,4 @@ chrono = { version = "0.4", features = ["serde"] } # Questions: async vs sync # which database to use? +# will probably substitute mobc* for sqlx and keep working with tokio. diff --git a/db.sql b/db.sql deleted file mode 100644 index bccefb6..0000000 --- a/db.sql +++ /dev/null @@ -1,85 +0,0 @@ -CREATE TABLE IF NOT EXISTS trees -( - id SERIAL PRIMARY KEY NOT NULL, - lat DECIMAL(15,10) NOT NULL, - lon DECIMAL(15,10) NOT NULL, - species VARCHAR(255),--do not use yet, data type may change - age INT, - health VARCHAR(255), --do not use yet, data type may change - created_at timestamp with time zone DEFAULT (now() at time zone 'utc'), -); - -CREATE TABLE IF NOT EXISTS houses -( - id SERIAL PRIMARY KEY NOT NULL, - name VARCHAR(255) NOT NULL, - built DATE NOT NULL, - torn_down DATE, - evicted BOOLEAN DEFAULT false NOT NULL, - icon VARCHAR(255) NOT NULL, - tree_id FOREIGN KEY REFERENCES trees(id) --- barrio_id FOREIGN KEY REFERENCES barrios(id) - created_at timestamp with time zone DEFAULT (now() at time zone 'utc'), -); - -CREATE TABLE IF NOT EXISTS barrios -( - id SERIAL PRIMARY KEY NOT NULL, - name VARCHAR(255) NOT NULL, - lat DECIMAL(15,10) NOT NULL, - lon DECIMAL(15,10) NOT NULL, - radius DECIMAL(15,10), -- area representation may change to fit leaflet - founded DATE NOT NULL, - dissolved DATE, - created_at timestamp with time zone DEFAULT (now() at time zone 'utc'), -); - -CREATE TABLE IF NOT EXISTS photos -( - id SERIAL PRIMARY KEY NOT NULL, - image_data MEDIUMBLOB NOT NULL, - license VARCHAR(255), - source VARCHAR(255), - taken_at timestamp with time zone, - created_at timestamp with time zone DEFAULT (now() at time zone 'utc'), -); - -CREATE TABLE IF NOT EXISTS stories -( - id SERIAL PRIMARY KEY NOT NULL, - author VARCHAR(255), - colour INT, -- format 0xrrggbb - text TEXT, - created_at timestamp with time zone DEFAULT (now() at time zone 'utc'), -); - -CREATE TABLE IF NOT EXISTS comments -( - id SERIAL PRIMARY KEY NOT NULL, - author VARCHAR(255), - colour INT, -- format 0xrrggbb - text TEXT, - parent_category INT, -- I'm looking for a better representation of a rust enum - parent_id INT, -- ^^ - created_at timestamp with time zone DEFAULT (now() at time zone 'utc'), -); - -CREATE TABLE IF NOT EXISTS tags -( - id SERIAL PRIMARY KEY NOT NULL, - parent_category INT, -- see above - parent_id INT, -- see above - child_category INT, -- see above - child_id INT, -- see above - created_at timestamp with time zone DEFAULT (now() at time zone 'utc'), -); - -CREATE TABLE IF NOT EXISTS users -( - id SERIAL PRIMARY KEY NOT NULL, - name VARCHAR(255), - passphrase VARCHAR(255), - colour INT, - role enum ('contributor','editor','admin'); - created_at timestamp with time zone DEFAULT (now() at time zone 'utc'), -); diff --git a/src/db.sql b/src/db.sql deleted file mode 100644 index 13f23a0..0000000 --- a/src/db.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE IF NOT EXISTS todo -( - id SERIAL PRIMARY KEY NOT NULL, - name VARCHAR(255), - created_at timestamp with time zone DEFAULT (now() at time zone 'utc'), - checked boolean DEFAULT false -);