1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
//! Core entities.
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
/// All the schema information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct Schema {
/// List of tables in the database.
pub(crate) tables: Vec<Table>,
/// List of relations in the database.
pub(crate) relations: Vec<Relation>,
/// Partial Tables
pub(crate) partial_tables: HashMap<String, Vec<String>>,
}
/// Table information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct TableColumn {
/// Column name.
pub(crate) column: String,
/// Column data type.
pub(crate) data_type: String,
/// Column index.
pub(crate) index: i32,
/// Column default.
pub(crate) default: Option<String>,
/// Column nullable.
pub(crate) nullable: String,
/// Column max chars.
pub(crate) max_chars: Option<i32>,
/// Column description.
pub(crate) description: Option<String>,
/// Table description.
pub(crate) table_description: Option<String>, // Redundant but easiest way to get it.
/// Column primary key.
pub(crate) primary_key: bool,
}
/// Table information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct Table {
/// Table name.
pub(crate) name: String,
/// Table Description
pub(crate) description: Option<String>,
/// List of fields.
pub(crate) fields: Vec<TableColumn>,
}
/// Row description.
//#[derive(Debug)]
// pub(crate)struct Field(pub(crate)FieldName, pub(crate)FieldType);
/// Relation node.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct Relation {
/// Table that the constraint references.
pub(crate) on_table: TableName,
/// Field that the constraint references.
pub(crate) on_field: FieldName,
/// Table which the fk references.
pub(crate) to_table: TableName,
/// Field which the fk references.
pub(crate) to_field: FieldName,
}
/// Table name
pub(crate) type TableName = String;
/// Field name
pub(crate) type FieldName = String;
// pub(crate)type FieldType = String;
/// Index Definition
pub(crate) struct Index {
/// Table name
pub(crate) table: TableName,
// pub(crate)name: String,
/// Primary Key
pub(crate) primary: bool,
// pub(crate)unique: bool,
/// Fields
pub(crate) fields: Vec<String>,
}