Feature Parity with python variant

This commit is contained in:
Neshura 2023-08-25 03:42:19 +02:00
parent 83bf813bb1
commit e19187d6c7
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
11 changed files with 3585 additions and 1 deletions

21
src/db/mod.rs Normal file
View 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
View 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,
}