Feature Parity with python variant
This commit is contained in:
parent
83bf813bb1
commit
e19187d6c7
11 changed files with 3585 additions and 1 deletions
src/db
21
src/db/mod.rs
Normal file
21
src/db/mod.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use std::error::Error;
|
||||
|
||||
use sqlx::{Postgres, postgres::PgConnectOptions, PgPool, Pool};
|
||||
|
||||
use crate::{PostgresConfig};
|
||||
|
||||
pub(crate) mod schemas;
|
||||
|
||||
pub(crate) async fn connect_postgres(config: PostgresConfig) -> Result<Pool<Postgres>, Box<dyn Error>> {
|
||||
|
||||
let connection_settings = PgConnectOptions::new()
|
||||
.host(&config.host)
|
||||
.port(config.port)
|
||||
.username(&config.user)
|
||||
.password(&config.password)
|
||||
.database(&config.db);
|
||||
|
||||
let pool = PgPool::connect_with(connection_settings).await?;
|
||||
|
||||
return Ok(pool);
|
||||
}
|
57
src/db/schemas.rs
Normal file
57
src/db/schemas.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use serde::Serialize;
|
||||
use sqlx::FromRow;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Serialize, ToSchema, Debug, FromRow)]
|
||||
pub struct PortraitGroup {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, ToSchema, Debug, FromRow)]
|
||||
pub struct Portrait {
|
||||
pub id: i32,
|
||||
pub group_id: i32,
|
||||
pub hires: String,
|
||||
pub lores: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, ToSchema, Debug, FromRow)]
|
||||
pub struct Game {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, ToSchema, Debug, FromRow)]
|
||||
pub struct GameGroup {
|
||||
pub id: i32,
|
||||
pub game_id: i32,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, ToSchema, Debug, FromRow)]
|
||||
pub struct Ethic {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub machine_ethic: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, ToSchema, Debug, FromRow)]
|
||||
pub struct Empire {
|
||||
pub id: i32,
|
||||
pub discord_user: Option<String>,
|
||||
pub group_id: i32,
|
||||
pub gestalt: Option<bool>, // TODO: make nn in DB schema
|
||||
pub empire_portrait_id: i32,
|
||||
pub empire_portrait_group_id: i32,
|
||||
pub group_game_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, ToSchema, Debug, FromRow)]
|
||||
pub struct EmpireEthic {
|
||||
pub empires_id: i32,
|
||||
pub empires_group_id: i32,
|
||||
pub empires_group_game_id: i32,
|
||||
pub ethics_id: i32,
|
||||
pub ethics_fanatic: bool,
|
||||
}
|
Reference in a new issue