use super::postgres_metadata::parsed::*;
use super::postgres_metadata::raw::*;
use super::*;
use bimap::BiBTreeMap;
use ciboulette::CibouletteIdType;
use getset::{CopyGetters, Getters, MutGetters};
use messy_json::*;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::sync::Arc;
use tracing::{trace, warn};
const POSTGRES_SYSTEM_COLUMNS: &[&str] =
&["oid", "tableoid", "xmin", "cmin", "xmax", "cmax", "ctid"];
const POSTGRES_SYSTEM_SCHEMA: &[&str] = &["pg_catalog", "pg_toast", "information_schema"];
mod builder;
mod config;
mod keys;
mod name;
mod objects;
mod relationships;
pub use builder::BasiliqStoreBuilder;
use builder::BasiliqStoreTableBuilder;
pub use config::{
BasiliqStoreConfig, BasiliqStoreConfigError, BasiliqStoreConfigMergeable,
BasiliqStoreRelationshipsConfig, BasiliqStoreResourceConfig,
};
#[derive(Debug, Clone, Getters)]
#[getset(get = "pub")]
pub struct BasiliqStore {
pub(crate) ciboulette: ciboulette::CibouletteStore,
pub(crate) tables: ciboulette2pg::Ciboulette2PgTableStore,
pub(crate) config: BasiliqStoreConfig,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Getters, Deserialize, Serialize)]
#[getset(get = "pub")]
pub struct BasiliqStoreTableIdentifier {
schema: String,
table: String,
}
impl BasiliqStoreTableIdentifier {
pub fn new(schema_name: &str, table_name: &str) -> Self {
BasiliqStoreTableIdentifier {
schema: schema_name.to_string(),
table: table_name.to_string(),
}
}
}
impl std::fmt::Display for BasiliqStoreTableIdentifier {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}__{}", self.schema, self.table)
}
}
impl From<&BasiliqDbScannedTable> for BasiliqStoreTableIdentifier {
fn from(table: &BasiliqDbScannedTable) -> Self {
BasiliqStoreTableIdentifier {
table: table.table().name().clone(),
schema: table.schema().name().clone(),
}
}
}
impl From<&BasiliqStoreResourceConfig> for BasiliqStoreTableIdentifier {
fn from(table: &BasiliqStoreResourceConfig) -> Self {
BasiliqStoreTableIdentifier {
table: table.target().table().clone(),
schema: table.target().schema().clone(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum BasiliqStoreRelationshipType {
OneToMany(bool),
ManyToOne(bool),
ManyToMany(BasiliqStoreRelationshipManyToManyData),
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Getters)]
#[getset(get = "pub")]
pub struct BasiliqStoreRelationshipManyToManyData {
bucket: BasiliqStoreTableIdentifier,
lfield_name: ArcStr,
ffield_name: ArcStr,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Getters, CopyGetters)]
pub struct BasiliqStoreRelationshipData {
#[getset(get = "pub")]
ltable: BasiliqStoreTableIdentifier,
#[getset(get = "pub")]
lfield_name: ArcStr,
#[getset(get = "pub")]
ftable: BasiliqStoreTableIdentifier,
#[getset(get = "pub")]
ffield_name: ArcStr,
#[getset(get = "pub")]
type_: BasiliqStoreRelationshipType,
#[getset(get_copy = "pub")]
optional: bool,
}