forked from jmug/stoatchat
Begin work on proper database schema.
This commit is contained in:
27
src/database/mod.rs
Normal file
27
src/database/mod.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use mongodb::{ Client, Collection, Database };
|
||||
use std::env;
|
||||
|
||||
use once_cell::sync::OnceCell;
|
||||
static DBCONN: OnceCell<Client> = OnceCell::new();
|
||||
|
||||
pub fn connect() {
|
||||
let client = Client::with_uri_str(
|
||||
&env::var("DB_URI").expect("DB_URI not in environment variables!"))
|
||||
.expect("Failed to init db connection.");
|
||||
|
||||
DBCONN.set(client).unwrap();
|
||||
}
|
||||
|
||||
pub fn get_connection() -> &'static Client {
|
||||
DBCONN.get().unwrap()
|
||||
}
|
||||
|
||||
pub fn get_db() -> Database {
|
||||
get_connection().database("revolt")
|
||||
}
|
||||
|
||||
pub fn get_collection(collection: &str) -> Collection {
|
||||
get_db().collection(collection)
|
||||
}
|
||||
|
||||
pub mod user;
|
||||
29
src/database/user.rs
Normal file
29
src/database/user.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use serde::{ Deserialize, Serialize };
|
||||
use bson::UtcDateTime;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct UserEmailVerification {
|
||||
pub verified: bool,
|
||||
pub target: Option<String>,
|
||||
pub expiry: Option<UtcDateTime>,
|
||||
pub rate_limit: Option<UtcDateTime>,
|
||||
pub code: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct UserRelationship {
|
||||
pub id: String,
|
||||
pub status: u8,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct User {
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
pub email: String,
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
pub access_token: Option<String>,
|
||||
pub email_verification: UserEmailVerification,
|
||||
pub relations: Option<Vec<UserRelationship>>,
|
||||
}
|
||||
Reference in New Issue
Block a user