#[derive(Debug, Clone)]
pub struct FullDB {
pub schemas: Vec<Schema>,
}
impl FullDB {
pub fn add_schema(&mut self, schema: Schema) {
self.schemas.push(schema);
}
pub fn no_types(&self) -> bool {
self.schemas.iter().all(|v| v.no_types())
}
pub fn no_procs(&self) -> bool {
self.schemas.iter().all(|v| v.no_procs())
}
}
#[derive(Debug, Clone)]
pub struct Schema {
pub id: SchemaId,
pub name: String,
pub owner_name: String,
pub types: Vec<PsqlType>,
pub procs: Vec<Vec<SqlProc>>,
}
impl Schema {
pub fn append_procs(&mut self, mut all_procs: Vec<Vec<SqlProc>>) {
self.procs.append(&mut all_procs);
}
pub fn append_types(&mut self, mut all_types: Vec<PsqlType>) {
self.types.append(&mut all_types);
}
pub fn no_types(&self) -> bool {
self.types.is_empty()
}
pub fn no_procs(&self) -> bool {
self.procs.is_empty()
}
}
pub type SchemaId = u32;
#[derive(Debug, Clone)]
pub struct PsqlType {
pub name: String,
pub ns: SchemaId,
pub typ: PsqlTypType,
}
#[derive(Debug, Clone)]
pub enum PsqlTypType {
Enum(PsqlEnumType),
Composite(PsqlCompositeType),
Base(PsqlBaseType),
Domain(PsqlDomain),
Other(u32),
SimpleComposite(NamesAndTypes),
}
#[derive(Debug, Clone)]
pub struct PsqlEnumType {
pub oid: u32,
pub labels: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct PsqlCompositeType {
pub oid: u32,
pub cols: Vec<Column>,
}
#[derive(Debug, Clone)]
pub struct Column {
pub pos: i16,
pub name: String,
pub type_id: u32,
pub type_name: String,
pub type_ns_name: String,
pub not_null: bool,
pub num_dimentions: i32,
}
#[derive(Debug, Clone)]
pub struct PsqlBaseType {
pub oid: u32,
pub name: String,
}
#[derive(Debug, Clone)]
pub struct PsqlDomain {
pub oid: u32,
pub base_oid: u32,
pub base_name: String,
pub base_ns_name: String,
}
#[derive(Debug, Clone)]
pub struct SqlProc {
pub ns: u32,
pub ns_name: String,
pub oid: u32,
pub name: String,
pub returns_set: bool,
pub num_args: i16,
pub inputs: NamesAndTypes,
pub outputs: FullType,
}
#[derive(Debug, Clone)]
pub struct NamesAndTypes(pub Vec<TypeAndName>);
#[derive(Debug, Clone)]
pub struct TypeAndName {
pub typ: FullType,
pub name: String,
}
#[derive(Debug, Clone)]
pub struct FullType {
pub schema: String,
pub name: String,
}