use crate::db_object::{DBObject, OrderTypes};
use crate::df_world::{DBDFWorld, HistoricalEvent};
use crate::schema::historical_events_n_o;
use crate::DbConnection;
use df_st_core::fillable::{Fillable, Filler};
use df_st_core::item_count::ItemCount;
use df_st_derive::Fillable;
use diesel::expression_methods::ExpressionMethods;
use diesel::prelude::*;
use diesel::query_dsl::RunQueryDsl;
use failure::Error;
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
#[derive(
Clone, Debug, AsChangeset, Identifiable, Associations, Queryable, Insertable, Fillable, Default,
)]
#[table_name = "historical_events_n_o"]
#[primary_key(he_id)]
#[belongs_to(HistoricalEvent, foreign_key = "he_id")]
pub struct HistoricalEventNO {
pub he_id: i32,
pub world_id: i32,
pub name_only: Option<bool>,
pub new_ab_id: Option<i32>,
pub new_account: Option<i32>,
pub new_artifact_id: Option<i32>,
pub new_caste: Option<i32>,
pub new_equipment_level: Option<i32>,
pub new_leader_hf_id: Option<i32>,
pub new_race_id: Option<String>,
pub new_site_civ_id: Option<i32>,
pub new_job: Option<String>,
pub new_structure_id: Option<i32>,
pub no_defeat_mention: Option<bool>,
pub no_prison_available: Option<bool>,
pub occasion_id: Option<i32>,
pub old_ab_id: Option<i32>,
pub old_account: Option<i32>,
pub old_artifact_id: Option<i32>,
pub old_caste: Option<i32>,
pub old_race_id: Option<String>,
pub outcome: Option<String>,
pub overthrown_hf_id: Option<i32>,
pub old_job: Option<String>,
pub old_structure_id: Option<i32>,
}
impl HistoricalEventNO {
pub fn new() -> Self {
Self::default()
}
}
impl DBObject<df_st_core::HistoricalEvent, HistoricalEventNO> for HistoricalEventNO {
fn add_missing_data_advanced(_core_world: &df_st_core::DFWorld, _world: &mut DBDFWorld) {
}
#[rustfmt::skip]
#[cfg(feature = "postgres")]
fn insert_into_db(conn: &DbConnection, historical_events_n_o: &[HistoricalEventNO]) {
use diesel::pg::upsert::excluded;
diesel::insert_into(historical_events_n_o::table)
.values(historical_events_n_o)
.on_conflict((
historical_events_n_o::he_id,
historical_events_n_o::world_id,
))
.do_update()
.set((
historical_events_n_o::name_only.eq(excluded(historical_events_n_o::name_only)),
historical_events_n_o::new_ab_id.eq(excluded(historical_events_n_o::new_ab_id)),
historical_events_n_o::new_account.eq(excluded(historical_events_n_o::new_account)),
historical_events_n_o::new_artifact_id.eq(excluded(historical_events_n_o::new_artifact_id)),
historical_events_n_o::new_caste.eq(excluded(historical_events_n_o::new_caste)),
historical_events_n_o::new_equipment_level.eq(excluded(historical_events_n_o::new_equipment_level)),
historical_events_n_o::new_leader_hf_id.eq(excluded(historical_events_n_o::new_leader_hf_id)),
historical_events_n_o::new_race_id.eq(excluded(historical_events_n_o::new_race_id)),
historical_events_n_o::new_site_civ_id.eq(excluded(historical_events_n_o::new_site_civ_id)),
historical_events_n_o::new_job.eq(excluded(historical_events_n_o::new_job)),
historical_events_n_o::new_structure_id.eq(excluded(historical_events_n_o::new_structure_id)),
historical_events_n_o::no_defeat_mention.eq(excluded(historical_events_n_o::no_defeat_mention)),
historical_events_n_o::no_prison_available.eq(excluded(historical_events_n_o::no_prison_available)),
historical_events_n_o::occasion_id.eq(excluded(historical_events_n_o::occasion_id)),
historical_events_n_o::old_ab_id.eq(excluded(historical_events_n_o::old_ab_id)),
historical_events_n_o::old_account.eq(excluded(historical_events_n_o::old_account)),
historical_events_n_o::old_artifact_id.eq(excluded(historical_events_n_o::old_artifact_id)),
historical_events_n_o::old_caste.eq(excluded(historical_events_n_o::old_caste)),
historical_events_n_o::old_race_id.eq(excluded(historical_events_n_o::old_race_id)),
historical_events_n_o::outcome.eq(excluded(historical_events_n_o::outcome)),
historical_events_n_o::overthrown_hf_id.eq(excluded(historical_events_n_o::overthrown_hf_id)),
historical_events_n_o::old_job.eq(excluded(historical_events_n_o::old_job)),
historical_events_n_o::old_structure_id.eq(excluded(historical_events_n_o::old_structure_id)),
))
.execute(conn)
.expect("Error saving historical_events_n_o");
}
#[cfg(not(feature = "postgres"))]
fn insert_into_db(conn: &DbConnection, historical_events_n_o: &[HistoricalEventNO]) {
diesel::insert_into(historical_events_n_o::table)
.values(historical_events_n_o)
.execute(conn)
.expect("Error saving historical_events_n_o");
}
fn find_db_list(
_conn: &DbConnection,
_id_filter: HashMap<String, i32>,
_string_filter: HashMap<String, String>,
_offset: i64,
_limit: i64,
_order: Option<OrderTypes>,
_order_by: Option<String>,
_id_list: Option<Vec<i32>>,
) -> Result<Vec<HistoricalEventNO>, Error> {
Ok(vec![])
}
fn find_db_item(
conn: &DbConnection,
id_filter: HashMap<String, i32>,
) -> Result<Option<HistoricalEventNO>, Error> {
use crate::schema::historical_events_n_o::dsl::*;
let query = historical_events_n_o;
let query = query.filter(world_id.eq(id_filter.get("world_id").unwrap_or(&0)));
let query = query.filter(he_id.eq(id_filter.get("he_id").unwrap_or(&0)));
Ok(query.first::<HistoricalEventNO>(conn).optional()?)
}
fn match_field_by(field: String) -> String {
match field.as_ref() {
"name_only" => "name_only",
"new_ab_id" => "new_ab_id",
"new_account" => "new_account",
"new_artifact_id" => "new_artifact_id",
"new_caste" => "new_caste",
"new_equipment_level" => "new_equipment_level",
"new_leader_hf_id" => "new_leader_hf_id",
"new_race_id" => "new_race_id",
"new_site_civ_id" => "new_site_civ_id",
"new_job" => "new_job",
"new_structure_id" => "new_structure_id",
"no_defeat_mention" => "no_defeat_mention",
"no_prison_available" => "no_prison_available",
"occasion_id" => "occasion_id",
"old_ab_id" => "old_ab_id",
"old_account" => "old_account",
"old_artifact_id" => "old_artifact_id",
"old_caste" => "old_caste",
"old_race_id" => "old_race_id",
"outcome" => "outcome",
"overthrown_hf_id" => "overthrown_hf_id",
"old_job" => "old_job",
"old_structure_id" => "old_structure_id",
_ => "he_id",
}
.to_owned()
}
fn add_nested_items(
_conn: &DbConnection,
_db_list: &[HistoricalEventNO],
core_list: Vec<df_st_core::HistoricalEvent>,
) -> Result<Vec<df_st_core::HistoricalEvent>, Error> {
Ok(core_list)
}
fn get_count_from_db(
_conn: &DbConnection,
_id_filter: HashMap<String, i32>,
_string_filter: HashMap<String, String>,
_offset: u32,
_limit: u32,
_group_by_opt: Option<String>,
_id_list: Option<Vec<i32>>,
) -> Result<Vec<ItemCount>, Error> {
Ok(vec![])
}
}
#[rustfmt::skip]
impl Filler<HistoricalEventNO, df_st_core::HistoricalEvent> for HistoricalEventNO {
fn add_missing_data(&mut self, source: &df_st_core::HistoricalEvent) {
self.he_id.add_missing_data(&source.id);
self.name_only.add_missing_data(&source.name_only);
self.new_ab_id.add_missing_data(&source.new_ab_id);
self.new_account.add_missing_data(&source.new_account);
self.new_artifact_id.add_missing_data(&source.new_artifact_id);
self.new_caste.add_missing_data(&source.new_caste);
self.new_equipment_level.add_missing_data(&source.new_equipment_level);
self.new_leader_hf_id.add_missing_data(&source.new_leader_hf_id);
self.new_race_id.add_missing_data(&source.new_race_id);
self.new_site_civ_id.add_missing_data(&source.new_site_civ_id);
self.new_job.add_missing_data(&source.new_job);
self.new_structure_id.add_missing_data(&source.new_structure_id);
self.no_defeat_mention.add_missing_data(&source.no_defeat_mention);
self.no_prison_available.add_missing_data(&source.no_prison_available);
self.occasion_id.add_missing_data(&source.occasion_id);
self.old_ab_id.add_missing_data(&source.old_ab_id);
self.old_account.add_missing_data(&source.old_account);
self.old_artifact_id.add_missing_data(&source.old_artifact_id);
self.old_caste.add_missing_data(&source.old_caste);
self.old_race_id.add_missing_data(&source.old_race_id);
self.outcome.add_missing_data(&source.outcome);
self.overthrown_hf_id.add_missing_data(&source.overthrown_hf_id);
self.old_job.add_missing_data(&source.old_job);
self.old_structure_id.add_missing_data(&source.old_structure_id);
}
}
#[rustfmt::skip]
impl Filler<df_st_core::HistoricalEvent, HistoricalEventNO> for df_st_core::HistoricalEvent {
fn add_missing_data(&mut self, source: &HistoricalEventNO) {
self.id.add_missing_data(&source.he_id);
self.name_only.add_missing_data(&source.name_only);
self.new_ab_id.add_missing_data(&source.new_ab_id);
self.new_account.add_missing_data(&source.new_account);
self.new_artifact_id.add_missing_data(&source.new_artifact_id);
self.new_caste.add_missing_data(&source.new_caste);
self.new_equipment_level.add_missing_data(&source.new_equipment_level);
self.new_leader_hf_id.add_missing_data(&source.new_leader_hf_id);
self.new_race_id.add_missing_data(&source.new_race_id);
self.new_site_civ_id.add_missing_data(&source.new_site_civ_id);
self.new_job.add_missing_data(&source.new_job);
self.new_structure_id.add_missing_data(&source.new_structure_id);
self.no_defeat_mention.add_missing_data(&source.no_defeat_mention);
self.no_prison_available.add_missing_data(&source.no_prison_available);
self.occasion_id.add_missing_data(&source.occasion_id);
self.old_ab_id.add_missing_data(&source.old_ab_id);
self.old_account.add_missing_data(&source.old_account);
self.old_artifact_id.add_missing_data(&source.old_artifact_id);
self.old_caste.add_missing_data(&source.old_caste);
self.old_race_id.add_missing_data(&source.old_race_id);
self.outcome.add_missing_data(&source.outcome);
self.overthrown_hf_id.add_missing_data(&source.overthrown_hf_id);
self.old_job.add_missing_data(&source.old_job);
self.old_structure_id.add_missing_data(&source.old_structure_id);
}
}
impl PartialEq for HistoricalEventNO {
fn eq(&self, other: &Self) -> bool {
self.he_id == other.he_id
}
}
impl Hash for HistoricalEventNO {
fn hash<H: Hasher>(&self, state: &mut H) {
self.he_id.hash(state);
}
}
impl PartialEq<HistoricalEventNO> for df_st_core::HistoricalEvent {
fn eq(&self, other: &HistoricalEventNO) -> bool {
self.id == other.he_id
}
}
impl PartialEq<df_st_core::HistoricalEvent> for HistoricalEventNO {
fn eq(&self, other: &df_st_core::HistoricalEvent) -> bool {
self.he_id == other.id
}
}