From f3e0570182c8e2573a8385aebcdba3aa4267eb2d Mon Sep 17 00:00:00 2001 From: shockrah Date: Tue, 4 Feb 2020 00:30:58 -0800 Subject: [PATCH] removing sub library and moving this code into our master codebase --- server/src/db_io/.env | 1 - server/src/db_io/.gitignore | 1 - server/src/db_io/Cargo.lock | 228 ------------------------------- server/src/db_io/Cargo.toml | 12 -- server/src/db_io/Makefile | 10 -- server/src/db_io/diesel.toml | 5 - server/src/db_io/scripts/conn.sh | 6 - server/src/db_io/src/lib.rs | 67 --------- server/src/db_io/src/models.rs | 22 --- server/src/db_io/src/schema.rs | 30 ---- 10 files changed, 382 deletions(-) delete mode 100644 server/src/db_io/.env delete mode 100644 server/src/db_io/.gitignore delete mode 100644 server/src/db_io/Cargo.lock delete mode 100644 server/src/db_io/Cargo.toml delete mode 100644 server/src/db_io/Makefile delete mode 100644 server/src/db_io/diesel.toml delete mode 100644 server/src/db_io/scripts/conn.sh delete mode 100644 server/src/db_io/src/lib.rs delete mode 100644 server/src/db_io/src/models.rs delete mode 100644 server/src/db_io/src/schema.rs diff --git a/server/src/db_io/.env b/server/src/db_io/.env deleted file mode 100644 index 1f99cb5..0000000 --- a/server/src/db_io/.env +++ /dev/null @@ -1 +0,0 @@ -export DATABASE_URL=mysql://freechat_server:@localhost/freechat_dev diff --git a/server/src/db_io/.gitignore b/server/src/db_io/.gitignore deleted file mode 100644 index 9dea3eb..0000000 --- a/server/src/db_io/.gitignore +++ /dev/null @@ -1 +0,0 @@ -dev/ diff --git a/server/src/db_io/Cargo.lock b/server/src/db_io/Cargo.lock deleted file mode 100644 index ca13299..0000000 --- a/server/src/db_io/Cargo.lock +++ /dev/null @@ -1,228 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "aho-corasick" -version = "0.6.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "byteorder" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "db_io" -version = "0.1.0" -dependencies = [ - "diesel 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "dotenv 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "diesel" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "diesel_derives 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "mysqlclient-sys 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "diesel_derives" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "dotenv" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "idna" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "matches" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "memchr" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "mysqlclient-sys" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", - "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "percent-encoding" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "pkg-config" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "proc-macro2" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "quote" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ucd-util 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "smallvec" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "syn" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "thread_local" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "ucd-util" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unicode-bidi" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "unicode-normalization" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "unicode-xid" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "url" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "utf8-ranges" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "vcpkg" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" -"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" -"checksum diesel 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9d7cc03b910de9935007861dce440881f69102aaaedfd4bc5a6f40340ca5840c" -"checksum diesel_derives 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3" -"checksum dotenv 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "400b347fe65ccfbd8f545c9d9a75d04b0caf23fec49aaa838a9a05398f94c019" -"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" -"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" -"checksum memchr 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3197e20c7edb283f87c071ddfc7a2cca8f8e0b888c242959846a6fce03c72223" -"checksum mysqlclient-sys 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7e9637d93448044078aaafea7419aed69d301b4a12bcc4aa0ae856eb169bef85" -"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" -"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" -"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" -"checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" -"checksum smallvec 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c2fb2ec9bcd216a5b0d0ccf31ab17b5ed1d627960edff65bbe95d3ce221cefc" -"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" -"checksum ucd-util 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "5ccdc2daea7cf8bc50cd8710d170a9d816678e54943829c5082bb1594312cf8e" -"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" -"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" -"checksum utf8-ranges 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba" -"checksum vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" diff --git a/server/src/db_io/Cargo.toml b/server/src/db_io/Cargo.toml deleted file mode 100644 index 2cd76cb..0000000 --- a/server/src/db_io/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "db_io" -version = "0.1.0" -authors = ["shockrah "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -diesel = { version = "1.0.0", features = ["mysql"] } -dotenv = "0.9.0" - diff --git a/server/src/db_io/Makefile b/server/src/db_io/Makefile deleted file mode 100644 index 25b300f..0000000 --- a/server/src/db_io/Makefile +++ /dev/null @@ -1,10 +0,0 @@ - -build: - cargo build - -test: -ifdef print - cargo test -- --nocapture -else - cargo test -endif diff --git a/server/src/db_io/diesel.toml b/server/src/db_io/diesel.toml deleted file mode 100644 index 92267c8..0000000 --- a/server/src/db_io/diesel.toml +++ /dev/null @@ -1,5 +0,0 @@ -# For documentation on how to configure this file, -# see diesel.rs/guides/configuring-diesel-cli - -[print_schema] -file = "src/schema.rs" diff --git a/server/src/db_io/scripts/conn.sh b/server/src/db_io/scripts/conn.sh deleted file mode 100644 index 09b8864..0000000 --- a/server/src/db_io/scripts/conn.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -# Connect to the given db via the .env file we have - -. ./dev/env - -mysql -u $DATABASE_USER -p $DATABASE_NAME -h $DATABASE_HOST diff --git a/server/src/db_io/src/lib.rs b/server/src/db_io/src/lib.rs deleted file mode 100644 index 4ef1de2..0000000 --- a/server/src/db_io/src/lib.rs +++ /dev/null @@ -1,67 +0,0 @@ -#[macro_use] -extern crate diesel; -extern crate dotenv; - -pub mod schema; -pub mod models; - -use diesel::prelude::*; -use schema::invites::dsl::*; -use models::Invite; -use std::env; - -struct DB { - conn: MysqlConnection, - url: String, -} - -fn get_conn() -> DB { - let url_ = env::var("DATABASE_URL") - .expect("DATABASE_URL not set!"); - - DB { - url: url_.clone(), - conn: MysqlConnection::establish(&url_) - .expect(&format!("Error connecting to {}", url_)), - } -} - -impl DB { - pub fn get_invite(&mut self) { - let connection = get_conn(); - let results = invites - .filter(uses.eq(1)) - .limit(5) - .load::(&connection.conn) - .expect("Error loading posts"); - - for i in results { - println!("hash {}", i.hash); - println!("uses {}", i.uses); - println!("timestamp {}", i.expire); - } - } -} - -#[cfg(test)] -mod tests { - extern crate diesel; - - use super::*; - //use super::models::*; - use super::diesel::prelude::*; - use super::dotenv::dotenv; - - #[test] - fn test_conn() { - dotenv().ok(); - let db = get_conn(); - println!("{}", db.url); - } - #[test] - fn get_conn_wrapper() { - dotenv().ok(); - let db = get_conn(); - println!("{}", db.url); - } -} diff --git a/server/src/db_io/src/models.rs b/server/src/db_io/src/models.rs deleted file mode 100644 index c7e966e..0000000 --- a/server/src/db_io/src/models.rs +++ /dev/null @@ -1,22 +0,0 @@ -#[derive(Serialize, Deserialize, Queryable)] -pub struct User { - pub id: u64, - pub strid: String, - display: String, - native: bool, -} - - -#[derive(Queryable)] -pub struct channels { - pub id: i64, - pub name: String, - pub ctype: i64, -} - -#[derive(Serialize, Deserialize, Queryable)] -pub struct Invite { - pub hash: i64, - pub uses: i32, // simple that tracks the number of uses a thing has left - pub expire: i64, // used as a unix time stamp -} diff --git a/server/src/db_io/src/schema.rs b/server/src/db_io/src/schema.rs deleted file mode 100644 index 7f8d1f7..0000000 --- a/server/src/db_io/src/schema.rs +++ /dev/null @@ -1,30 +0,0 @@ -table! { - channels (id) { - id -> Integer, - name -> Varchar, - ctype -> Integer, - } -} - -table! { - invites (id) { - id -> Integer, - uses -> Nullable, - expire -> Nullable, - } -} - -table! { - users (id) { - id -> Integer, - strid -> Nullable, - display -> Nullable, - native -> Nullable, - } -} - -allow_tables_to_appear_in_same_query!( - channels, - invites, - users, -);