diff --git a/src/main.rs b/src/main.rs index ba61402..31b1c7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,6 @@ enum Operation { Insert(TableName, InsertionValues), Delete(TableName, Option), // Update(...), - // CreateTable(TableName, TableSchema), CreateIndex(TableName, ColumnName), // TODO: Is this sufficient? // DropTable(TableName), @@ -51,6 +50,7 @@ enum DbValue { Int(u64), Number(f64), UUID(UUID), + // TODO: what bout null? } // TODO: Can this be autogenerated from the values? @@ -82,7 +82,8 @@ type TablePosition = u32; struct Table { schema: TableSchema, - rows: Rows, + rows: Rows, // TODO: Consider wrapping this in a lock. Also consider if we need to have the + // same lock for both rows and indexes indexes: HashMap // TODO: Consider generalizing `ColumnPosition` to something that would also apply to a pair of `ColumnNames` etc } @@ -115,8 +116,13 @@ type ColumnPosition = u32; type Row = Vec; type Rows = + // TODO: This should be some sort of an interface to a dictionary + // s.t. in the background it may modify stuff in memory or talk to the disk BTreeMap; + // interface + // insert(id, value) + // ==============Interpreter================ struct State { table_positions: HashMap, @@ -200,14 +206,44 @@ impl Table { } fn select_where(&self, column_selection: ColumnSelection, maybe_condition: Option, consumer: impl SqlConsumer) { - todo!() + match maybe_condition { + None => { + // .iter() will give us an iterator over all the rows + + // two choices + // 1. optimized version + // self.iter_with_columns(column_selection).for_each(|row| { + // consumer.send(row) + // }); + // 2. + // self.iter() + // .map(|row| row.select_columns(column_selection)) + // .for_each(|reduced_row| { + // consumer.send(row) + // }); + todo!() + }, + Some(Condition::Eq(column_name, value)) => { + // is column_name primary key? then it is easy + // self.get(id) + // is column_name indexed? Then get the index, and then it is not easy, because you + // may get a set of ids. + // what if it is not primary nor indexed? then you need to brute force your way + // through the whole table? + todo!() + } + } } fn insert(&mut self, values: InsertionValues, consumer: impl SqlConsumer) { + // 1. You need to update indices + // 2. you simply insert the data todo!() } fn delete_where(&mut self, maybe_condition: Option, consumer: impl SqlConsumer) { + // kinda similar to select with respect to the conditions + // update index todo!() } }