Move Column into schema.rs
This commit is contained in:
parent
0ec02eeef8
commit
a2180a3e32
9 changed files with 23 additions and 24 deletions
|
|
@ -4,8 +4,7 @@ use std::ops::{Index, IndexMut};
|
|||
use std::slice::SliceIndex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::restricted_row::RestrictedRow;
|
||||
|
||||
pub type Column = usize;
|
||||
use crate::schema::Column;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Row(Vec<Value>);
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
use crate::error::RuntimeError;
|
||||
use crate::internals::column_index::ColumnIndex;
|
||||
use crate::internals::row::{Column, Row};
|
||||
use crate::internals::row::Row;
|
||||
use crate::restricted_row::RestrictedRow;
|
||||
use crate::schema::{ColumnName, TableSchema, TableName};
|
||||
use crate::schema::{Column, ColumnName, TableSchema, TableName};
|
||||
use crate::result::DbResult;
|
||||
use crate::type_system::{IndexableValue, Uuid, Value};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use crate::internals::row::Column;
|
||||
use crate::schema::{TableName, TableSchema};
|
||||
use crate::schema::{Column, TableName, TableSchema};
|
||||
use crate::internals::table::Table;
|
||||
use crate::operation::{Operation, Condition};
|
||||
use crate::result::DbResult;
|
||||
|
|
@ -145,7 +144,7 @@ impl State {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::internals::row::Column;
|
||||
use crate::schema::Column;
|
||||
use std::collections::HashSet;
|
||||
use crate::type_system::{DbType, IndexableValue, Value};
|
||||
use crate::operation::Operation;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use crate::schema::TableSchema;
|
||||
use crate::schema::{Column, TableSchema};
|
||||
use crate::type_system::Value;
|
||||
use crate::internals::row::Column;
|
||||
use crate::interpreter::TablePosition;
|
||||
|
||||
// Validated operation. Constructed by validation crate.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::ops::Index;
|
||||
use std::slice::SliceIndex;
|
||||
use crate::internals::row::Column;
|
||||
use crate::schema::Column;
|
||||
use crate::type_system::Value;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::internals::row::{Column, Row};
|
||||
use crate::internals::row::Row;
|
||||
use crate::operation::{InsertionValues, ColumnSelection};
|
||||
use crate::result::DbResult;
|
||||
use crate::type_system::{DbType, IndexableValue, Uuid, Value};
|
||||
|
|
@ -17,6 +17,8 @@ pub struct TableSchema {
|
|||
|
||||
pub type TableName = String;
|
||||
pub type ColumnName = String;
|
||||
pub type Column = usize;
|
||||
|
||||
|
||||
impl TableSchema {
|
||||
pub fn new(table_name: TableName, primary_column_name: ColumnName, columns: Vec<ColumnName>, types: Vec<DbType>) -> Self {
|
||||
|
|
@ -47,7 +49,7 @@ impl TableSchema {
|
|||
self.column_name_position_mapping.contains_left(column_name)
|
||||
}
|
||||
|
||||
pub fn get_column_position(&self, column_name: &ColumnName) -> Option<Column> {
|
||||
pub fn get_column(&self, column_name: &ColumnName) -> Option<Column> {
|
||||
self.column_name_position_mapping.get_by_left(column_name).copied()
|
||||
}
|
||||
|
||||
|
|
@ -57,13 +59,13 @@ impl TableSchema {
|
|||
selection
|
||||
}
|
||||
|
||||
pub fn get_column(&self, column_name: &ColumnName) -> Option<(Column, DbType)> {
|
||||
let column = self.get_column_position(column_name)?;
|
||||
pub fn get_typed_column(&self, column_name: &ColumnName) -> Option<(Column, DbType)> {
|
||||
let column = self.get_column(column_name)?;
|
||||
Some((column, self.column_type(column)))
|
||||
}
|
||||
|
||||
pub fn get_type_at(&self, column_name: &ColumnName) -> Option<DbType> {
|
||||
let position = self.get_column_position(column_name)?;
|
||||
let position = self.get_column(column_name)?;
|
||||
self.types.get(position).copied()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue