feat: finish work on server
This commit is contained in:
parent
7b79dd69b4
commit
51ed3bbc5c
9 changed files with 356 additions and 145 deletions
|
|
@ -8,3 +8,4 @@ edition = "2021"
|
|||
[dependencies]
|
||||
bimap = "0.6.3"
|
||||
thiserror = "1.0.50"
|
||||
tokio = { version = "1.35.1", features = ["sync"] }
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::sync::Arc;
|
||||
use crate::error::Error;
|
||||
use crate::internals::row::ColumnPosition;
|
||||
use crate::schema::{TableName, TableSchema};
|
||||
|
|
@ -6,6 +7,7 @@ use crate::operation::{ColumnSelection, Condition, Operation};
|
|||
use crate::result::DbResult;
|
||||
use crate::type_system::{DbType, IndexableValue, Value};
|
||||
use bimap::BiMap;
|
||||
use tokio::sync::Mutex;
|
||||
use crate::restricted_row::RestrictedRow;
|
||||
|
||||
// Use `TablePosition` as index
|
||||
|
|
@ -21,7 +23,7 @@ pub struct State {
|
|||
|
||||
// #[derive(Debug)]
|
||||
pub enum Response<'a> {
|
||||
Selected(&'a TableSchema, Box<dyn Iterator<Item=RestrictedRow> + 'a>),
|
||||
Selected(&'a TableSchema, Arc<Mutex<dyn Iterator<Item=RestrictedRow> + 'a + Send>>),
|
||||
Inserted,
|
||||
Deleted(usize), // how many were deleted
|
||||
TableCreated,
|
||||
|
|
@ -49,7 +51,7 @@ impl std::fmt::Debug for Response<'_> {
|
|||
}
|
||||
|
||||
impl State {
|
||||
fn new() -> Self {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
table_name_position_mapping: BiMap::new(),
|
||||
tables: vec![],
|
||||
|
|
@ -100,7 +102,7 @@ impl State {
|
|||
let selected_rows = match maybe_condition {
|
||||
None => {
|
||||
let x = table.select_all_rows(selected_column_positions);
|
||||
Box::new(x) as Box<dyn Iterator<Item=RestrictedRow> + 'a>
|
||||
Arc::new(Mutex::new(x)) as Arc<Mutex<dyn Iterator<Item=RestrictedRow> + 'a + Send>>
|
||||
},
|
||||
|
||||
Some(Condition::Eq(eq_column_name, value)) => {
|
||||
|
|
@ -113,7 +115,7 @@ impl State {
|
|||
eq_column_position,
|
||||
value,
|
||||
)?;
|
||||
Box::new(x) as Box<dyn Iterator<Item=RestrictedRow> + 'a>
|
||||
Arc::new(Mutex::new(x)) as Arc<Mutex<dyn Iterator<Item=RestrictedRow> + 'a + Send>>
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use crate::type_system::Value;
|
|||
// Perhaps consider factoring the table name out
|
||||
// and think of the operations as operating on a unique table.
|
||||
// TODO: `TableName` should be replaced by `TablePosition`
|
||||
#[derive(Debug)]
|
||||
pub enum Operation {
|
||||
Select(TableName, ColumnSelection, Option<Condition>),
|
||||
Insert(TableName, InsertionValues),
|
||||
|
|
@ -18,11 +19,13 @@ pub enum Operation {
|
|||
|
||||
pub type InsertionValues = Vec<(ColumnName, Value)>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ColumnSelection {
|
||||
All,
|
||||
Columns(Vec<ColumnName>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Condition {
|
||||
// And(Box<Condition>, Box<Condition>),
|
||||
// Or(Box<Condition>, Box<Condition>),
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ pub type TableName = String;
|
|||
pub type ColumnName = String;
|
||||
|
||||
impl TableSchema {
|
||||
pub(crate) fn new(table_name: TableName, primary_key: ColumnPosition, column_name_position_map: Vec<(ColumnName, ColumnPosition)>, types: Vec<DbType>) -> Self {
|
||||
pub fn new(table_name: TableName, primary_key: ColumnPosition, column_name_position_map: Vec<(ColumnName, ColumnPosition)>, types: Vec<DbType>) -> Self {
|
||||
let mut column_name_position_mapping: BiMap<ColumnName, ColumnPosition> = BiMap::new();
|
||||
for (column_name, column_position) in column_name_position_map {
|
||||
column_name_position_mapping.insert(column_name, column_position);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue