diff options
| author | Fuwn <[email protected]> | 2021-05-20 17:05:59 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-20 17:05:59 +0000 |
| commit | 9dbc613765de8ab7dfa8e1374cf6661dcfd56bc8 (patch) | |
| tree | 8cfff6a23bb72db2660e68c63a8cf9d0539a061f /crates/whirl_db/src | |
| parent | feat(readme): add sqlfluff as a dev dep (diff) | |
| download | whirl-9dbc613765de8ab7dfa8e1374cf6661dcfd56bc8.tar.xz whirl-9dbc613765de8ab7dfa8e1374cf6661dcfd56bc8.zip | |
refactor(global): move crates around, stricter module isolation
Diffstat (limited to 'crates/whirl_db/src')
| -rw-r--r-- | crates/whirl_db/src/lib.rs | 48 | ||||
| -rw-r--r-- | crates/whirl_db/src/models.rs | 50 | ||||
| -rw-r--r-- | crates/whirl_db/src/schema.rs | 35 |
3 files changed, 133 insertions, 0 deletions
diff --git a/crates/whirl_db/src/lib.rs b/crates/whirl_db/src/lib.rs new file mode 100644 index 0000000..35f05ae --- /dev/null +++ b/crates/whirl_db/src/lib.rs @@ -0,0 +1,48 @@ +// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +#![feature( + type_ascription, + hash_set_entry, + type_name_of_val, + decl_macro, + proc_macro_hygiene +)] +#![warn(rust_2018_idioms)] +#![recursion_limit = "128"] + +#[macro_use] +extern crate diesel; + +pub mod models; +mod schema; + +use diesel::prelude::*; + +// use crate::db::models::*; + +pub fn establish_connection() -> SqliteConnection { + let database_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| "whirl.sqlite3".to_string()); + SqliteConnection::establish(&database_url) + .unwrap_or_else(|_| panic!("error connecting to {}", database_url)) +} + +/// Only works if you have a valid database already setup! +#[cfg(test)] +#[test] +#[ignore] +pub fn show_serials() { + use crate::{models::SerialNumber, schema::serial_numbers::dsl::*}; + + dotenv::dotenv().ok(); + + let results = serial_numbers + .limit(5) + .load::<SerialNumber>(&establish_connection()) + .expect("error loading serial numbers table"); + + println!("found {} results", results.len()); + for result in results { + println!("{}", result.user_name); + } +} diff --git a/crates/whirl_db/src/models.rs b/crates/whirl_db/src/models.rs new file mode 100644 index 0000000..52304b6 --- /dev/null +++ b/crates/whirl_db/src/models.rs @@ -0,0 +1,50 @@ +// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +//! Much of the documentation that you will see within this module is quoted +//! from http://dev.worlds.net/private/GammaDocs/WorldServer.html#RoomServer. + +// use crate::db::schema::*; + +// -------------- +// | Queryables | +// -------------- + +#[derive(Queryable, Debug)] +pub struct SerialNumber { + pub serial_number: String, + pub user_name: String, + pub serial_status: i32, +} + +#[derive(Queryable, Debug)] +pub struct UserRegistration { + pub user_name_lower: String, + pub user_name: String, + pub serial_number: String, + pub password: String, + pub client_version: String, + pub account_status: i32, + pub registration_date: String, + pub times_on: i32, + pub total_minutes: i32, + pub user_privileges: i32, +} + +#[derive(Queryable, Debug)] +pub struct UserProperty { + pub user_name: String, + pub property_id: i32, + pub property_flags: i32, + pub property_access: i32, + pub property_string_value: String, + pub property_binary_value: String, +} + +// --------------- +// | Insertables | +// --------------- + +// -------------- +// | Updatables | +// -------------- diff --git a/crates/whirl_db/src/schema.rs b/crates/whirl_db/src/schema.rs new file mode 100644 index 0000000..6d58598 --- /dev/null +++ b/crates/whirl_db/src/schema.rs @@ -0,0 +1,35 @@ +table! { + serial_numbers (user_name) { + serial_number -> Text, + user_name -> Text, + serial_status -> Integer, + } +} + +table! { + user_properties (user_name) { + user_name -> Text, + property_id -> Integer, + property_flags -> Integer, + property_access -> Integer, + property_string_value -> Integer, + property_binary_value -> Nullable<Text>, + } +} + +table! { + user_registration (user_name) { + user_name_lower -> Text, + user_name -> Text, + serial_number -> Text, + password -> Text, + client_version -> Text, + account_status -> Integer, + registration_date -> Text, + times_on -> Integer, + total_minutes -> Integer, + user_privileges -> Integer, + } +} + +allow_tables_to_appear_in_same_query!(serial_numbers, user_properties, user_registration,); |