You've already forked AstralRinth
forked from didirus/AstralRinth
Basic Database
This commit is contained in:
11
src/database/database.rs
Normal file
11
src/database/database.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use diesel::prelude::*;
|
||||
use diesel::pg::PgConnection;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
|
||||
pub fn connect() -> PgConnection{
|
||||
dotenv.ok();
|
||||
|
||||
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set!");
|
||||
PgConnection::establish(&database_url).expect(&format!("Error connecting to {}", database_url))
|
||||
}
|
||||
6
src/database/mod.rs
Normal file
6
src/database/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
mod database;
|
||||
mod models;
|
||||
|
||||
pub use database::connect;
|
||||
pub use models::Mod;
|
||||
pub use models::Version;
|
||||
31
src/database/models.rs
Normal file
31
src/database/models.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::schema::mods;
|
||||
|
||||
#[derive(Queryable)]
|
||||
pub struct Mod {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub published: String,
|
||||
pub author: String,
|
||||
pub downloads: i32,
|
||||
pub categories: Vec<String>,
|
||||
pub body_path: String,
|
||||
pub icon_path: String
|
||||
}
|
||||
|
||||
#[derive(Queryable)]
|
||||
pub struct Version {
|
||||
pub id: i32,
|
||||
pub mod_id: i32,
|
||||
pub title: String,
|
||||
pub changelog_path: String,
|
||||
pub files_path: Vec<String>,
|
||||
pub date_published: String,
|
||||
pub author: String,
|
||||
pub downloads: i32,
|
||||
pub dependencies: Vec<String>,
|
||||
pub game_versions: Vec<String>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user