Merge branch 'main' into server-work
This commit is contained in:
commit
e87b11f19f
12 changed files with 190 additions and 138 deletions
|
|
@ -12,8 +12,8 @@ use std::collections::HashMap;
|
|||
pub struct TableSchema {
|
||||
table_name: TableName, // used for descriptive errors
|
||||
primary_key: ColumnPosition,
|
||||
pub column_name_position_mapping: BiMap<ColumnName, ColumnPosition>,
|
||||
pub types: Vec<DbType>,
|
||||
column_name_position_mapping: BiMap<ColumnName, ColumnPosition>,
|
||||
types: Vec<DbType>,
|
||||
}
|
||||
|
||||
pub type TableName = String;
|
||||
|
|
@ -36,6 +36,24 @@ impl TableSchema {
|
|||
self.types[column_position]
|
||||
}
|
||||
|
||||
pub fn get_columns(&self) -> Vec<&ColumnName> {
|
||||
self.column_name_position_mapping.iter().map(|(name, _)| name).collect()
|
||||
}
|
||||
|
||||
pub fn does_column_exist(&self, column_name: &ColumnName) -> bool {
|
||||
self.column_name_position_mapping.contains_left(column_name)
|
||||
}
|
||||
|
||||
pub fn get_column_position(&self, column_name: &ColumnName) -> Option<ColumnPosition> {
|
||||
self.column_name_position_mapping.get_by_left(column_name).copied()
|
||||
}
|
||||
|
||||
pub fn get_type_at(&self, column_name: &ColumnName) -> Option<DbType> {
|
||||
let position = self.get_column_position(column_name)?;
|
||||
self.types.get(position).copied()
|
||||
}
|
||||
|
||||
// TODO: Get rid of this after validation is merged
|
||||
fn get_column(&self, column_name: &ColumnName) -> DbResult<(DbType, ColumnPosition)> {
|
||||
match self.column_name_position_mapping.get_by_left(column_name) {
|
||||
Some(column_position) => match self.types.get(*column_position) {
|
||||
|
|
@ -52,6 +70,7 @@ impl TableSchema {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Get rid of this after validation is merged
|
||||
pub fn column_position_from_column_name(
|
||||
&self,
|
||||
column_name: &ColumnName,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue