This repository has been archived by the owner on Apr 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated index and constraint definition into the table objects. Ne…
…ed to continue to implement.
- Loading branch information
Showing
25 changed files
with
621 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//! This defines all the system internal tables so we can bootstrap the system. | ||
use super::super::engine::objects::Table; | ||
use std::sync::Arc; | ||
|
||
pub mod pg_attribute; | ||
pub mod pg_class; | ||
pub mod pg_constraint; | ||
pub mod pg_index; | ||
|
||
#[derive(Copy, Clone)] | ||
pub enum SystemTables { | ||
PgAttribute, //Columns | ||
PgClass, //Tables | ||
PgConstraint, | ||
PgIndex, | ||
} | ||
|
||
impl SystemTables { | ||
//TODO Should this be removed? | ||
pub const VALUES: [SystemTables; 4] = [ | ||
SystemTables::PgAttribute, | ||
SystemTables::PgClass, | ||
SystemTables::PgConstraint, | ||
SystemTables::PgIndex, | ||
]; | ||
pub fn value(self) -> Arc<Table> { | ||
match self { | ||
SystemTables::PgClass => pg_class::get_table(), | ||
SystemTables::PgAttribute => pg_attribute::get_table(), | ||
SystemTables::PgConstraint => pg_constraint::get_table(), | ||
SystemTables::PgIndex => pg_index::get_table(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use crate::constants::Nullable; | ||
use crate::engine::objects::{ | ||
types::{BaseSqlTypesMapper, SqlTypeDefinition}, | ||
Attribute, Constraint, Index, PrimaryKeyConstraint, Table, | ||
}; | ||
use hex_literal::hex; | ||
use std::sync::Arc; | ||
use uuid::Uuid; | ||
|
||
pub const id: Uuid = Uuid::from_bytes(hex!("EE89957F3E9F482C836DDA6C349AC632")); | ||
pub const name: &str = "pg_attribute"; | ||
|
||
pub const column_class_id: &str = "class_id"; | ||
pub const column_name: &str = "name"; | ||
pub const column_sql_type: &str = "type_name"; | ||
pub const column_column_num: &str = "column_num"; | ||
pub const column_nullable: &str = "nullable"; | ||
|
||
pub fn get_columns() -> Vec<Attribute> { | ||
vec![ | ||
Attribute::new( | ||
column_class_id.to_string(), | ||
BaseSqlTypesMapper::Uuid, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_name.to_string(), | ||
BaseSqlTypesMapper::Text, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_sql_type.to_string(), | ||
BaseSqlTypesMapper::Text, //TODO join to pg_type instead, for now its a string | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_column_num.to_string(), | ||
BaseSqlTypesMapper::Integer, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_nullable.to_string(), | ||
BaseSqlTypesMapper::Bool, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
] | ||
} | ||
|
||
pub fn get_index(attrs: &Vec<Attribute>) -> Arc<Index> { | ||
Arc::new(Index { | ||
id: Uuid::from_bytes(hex!("516B20412CF145A2AD9E39A8BDEB30A8")), | ||
name: name.to_string() + "_name_index", | ||
columns: Arc::new(SqlTypeDefinition::new(&[attrs[1].clone()])), | ||
unique: true, | ||
}) | ||
} | ||
|
||
pub fn get_table() -> Arc<Table> { | ||
let columns = get_columns(); | ||
let index = get_index(&columns); | ||
Arc::new(Table::new( | ||
id, | ||
name.to_string(), | ||
get_columns(), | ||
vec![Constraint::PrimaryKey(PrimaryKeyConstraint { | ||
name: index.name.clone() + "_primary_key", | ||
index: index.clone(), | ||
})], | ||
vec![index], | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::constants::Nullable; | ||
use crate::engine::objects::{ | ||
types::{BaseSqlTypesMapper, SqlTypeDefinition}, | ||
Attribute, Constraint, Index, PrimaryKeyConstraint, Table, | ||
}; | ||
use hex_literal::hex; | ||
use std::sync::Arc; | ||
use uuid::Uuid; | ||
|
||
pub const id: Uuid = Uuid::from_bytes(hex!("EE919E33D9054F4889537EBB6CC911EB")); | ||
pub const name: &str = "pg_class"; | ||
|
||
pub const column_id: &str = "id"; | ||
pub const column_name: &str = "name"; | ||
|
||
pub fn get_columns() -> Vec<Attribute> { | ||
vec![ | ||
Attribute::new( | ||
column_id.to_string(), | ||
BaseSqlTypesMapper::Uuid, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_name.to_string(), | ||
BaseSqlTypesMapper::Text, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
] | ||
} | ||
|
||
pub fn get_index(attrs: &Vec<Attribute>) -> Arc<Index> { | ||
Arc::new(Index { | ||
id: Uuid::from_bytes(hex!("516B20412CF145A2AD9E39A8BDEB30A8")), | ||
name: name.to_string() + "_name_index", | ||
columns: Arc::new(SqlTypeDefinition::new(&[attrs[1].clone()])), | ||
unique: true, | ||
}) | ||
} | ||
|
||
pub fn get_table() -> Arc<Table> { | ||
let columns = get_columns(); | ||
let index = get_index(&columns); | ||
Arc::new(Table::new( | ||
id, | ||
name.to_string(), | ||
columns, | ||
vec![Constraint::PrimaryKey(PrimaryKeyConstraint { | ||
name: name.to_string() + "_primary_key", | ||
index: index.clone(), | ||
})], | ||
vec![index], | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use crate::constants::Nullable; | ||
use crate::engine::objects::{ | ||
types::{BaseSqlTypesMapper, SqlTypeDefinition}, | ||
Attribute, Constraint, Index, PrimaryKeyConstraint, Table, | ||
}; | ||
use hex_literal::hex; | ||
use std::sync::Arc; | ||
use uuid::Uuid; | ||
|
||
pub const id: Uuid = Uuid::from_bytes(hex!("DB6AB6BB401B4071BE52763C0C550600")); | ||
pub const name: &str = "pg_constraint"; | ||
|
||
pub const column_id: &str = "id"; | ||
pub const column_class_id: &str = "class_id"; | ||
pub const column_index_id: &str = "index_id"; | ||
pub const column_name: &str = "name"; | ||
pub const column_type: &str = "type"; | ||
|
||
pub fn get_columns() -> Vec<Attribute> { | ||
vec![ | ||
Attribute::new( | ||
column_id.to_string(), | ||
BaseSqlTypesMapper::Uuid, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_class_id.to_string(), | ||
BaseSqlTypesMapper::Uuid, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_index_id.to_string(), | ||
BaseSqlTypesMapper::Uuid, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_name.to_string(), | ||
BaseSqlTypesMapper::Text, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_type.to_string(), | ||
BaseSqlTypesMapper::Text, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
] | ||
} | ||
|
||
pub fn get_index(attrs: &Vec<Attribute>) -> Arc<Index> { | ||
Arc::new(Index { | ||
id: Uuid::from_bytes(hex!("27182DE783AB42D8B5DD43BFC0154F0F")), | ||
name: name.to_string() + "_name_index", | ||
columns: Arc::new(SqlTypeDefinition::new(&[attrs[3].clone()])), | ||
unique: true, | ||
}) | ||
} | ||
|
||
pub fn get_table() -> Arc<Table> { | ||
let columns = get_columns(); | ||
let index = get_index(&columns); | ||
Arc::new(Table::new( | ||
id, | ||
name.to_string(), | ||
columns, | ||
vec![Constraint::PrimaryKey(PrimaryKeyConstraint { | ||
name: name.to_string() + "_primary_key", | ||
index: index.clone(), | ||
})], | ||
vec![index], | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use crate::constants::Nullable; | ||
use crate::engine::objects::{ | ||
types::{BaseSqlTypesMapper, SqlTypeDefinition}, | ||
Attribute, Constraint, Index, PrimaryKeyConstraint, Table, | ||
}; | ||
use hex_literal::hex; | ||
use std::sync::Arc; | ||
use uuid::Uuid; | ||
|
||
pub const id: Uuid = Uuid::from_bytes(hex!("3AB3B076A0EA46E186130F088D06FA02")); | ||
pub const name: &str = "pg_index"; | ||
|
||
pub const column_id: &str = "id"; | ||
pub const column_class_id: &str = "class_id"; | ||
pub const column_name: &str = "name"; | ||
pub const column_attributes: &str = "attributes"; | ||
pub const column_unique: &str = "unique"; | ||
|
||
pub fn get_columns() -> Vec<Attribute> { | ||
vec![ | ||
Attribute::new( | ||
column_id.to_string(), | ||
BaseSqlTypesMapper::Uuid, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_class_id.to_string(), | ||
BaseSqlTypesMapper::Uuid, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_name.to_string(), | ||
BaseSqlTypesMapper::Text, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_attributes.to_string(), | ||
BaseSqlTypesMapper::Array(Arc::new(BaseSqlTypesMapper::Integer)), | ||
Nullable::NotNull, | ||
None, | ||
), | ||
Attribute::new( | ||
column_unique.to_string(), | ||
BaseSqlTypesMapper::Bool, | ||
Nullable::NotNull, | ||
None, | ||
), | ||
] | ||
} | ||
|
||
pub fn get_index(attrs: &Vec<Attribute>) -> Arc<Index> { | ||
Arc::new(Index { | ||
id: Uuid::from_bytes(hex!("5F59466782874C568F1C0C09E99C9249")), | ||
name: name.to_string() + "_name_index", | ||
columns: Arc::new(SqlTypeDefinition::new(&[attrs[2].clone()])), | ||
unique: true, | ||
}) | ||
} | ||
|
||
pub fn get_table() -> Arc<Table> { | ||
let columns = get_columns(); | ||
let index = get_index(&columns); | ||
Arc::new(Table::new( | ||
id, | ||
name.to_string(), | ||
columns, | ||
vec![Constraint::PrimaryKey(PrimaryKeyConstraint { | ||
name: name.to_string() + "_primary_key", | ||
index: index.clone(), | ||
})], | ||
vec![index], | ||
)) | ||
} |
Oops, something went wrong.