diff --git a/src/main.rs b/src/main.rs index 02bc1cb..d5173cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,44 @@ struct InputBuffer { buffer: Option, } +enum MetaCommandResult { + Success, + Unrecognized, +} + +enum PrepareResult { + Success, + Unrecognized, +} + +enum StatementType { + Insert, + Select, +} + +struct Statement { + statement_type: StatementType, +} + +impl Statement { + fn new(statement_type: StatementType) -> Self { + Self { + statement_type + } + } + + pub(crate) fn execute(&self) { + match self.statement_type { + StatementType::Insert => { + println!("This is where you do an insert") + } + StatementType::Select => { + println!("This is where you do an select") + } + } + } +} + impl InputBuffer { pub fn new() -> Self { return Self { @@ -38,18 +76,40 @@ impl InputBuffer { pub(crate) fn parse(&self) { match &self.buffer { Some(command) => { - match command.as_str().replace("\n", "").trim() { - ".exit" => { - exit(0); - } - cmd => { - println!("Could not handle command: {cmd}") + if command.starts_with(".") { + Self::handle_meta_statement(command); + } else { + if let Ok(statement) = Self::prepare_statement(command) { + statement.execute() + } else { + println!("could not recognize statement"); } } } None => {} } } + + fn prepare_statement(command: &String) -> Result { + if command.starts_with("insert") { + Ok(Statement::new(StatementType::Insert)) + } else if command.starts_with("select") { + Ok(Statement::new(StatementType::Select)) + } else { + Err(String::from("Unrecognized statement")) + } + } + + fn handle_meta_statement(command: &String) { + match command.replace("\n", "").trim() { + ".exit" => { + exit(0); + } + cmd => { + println!("Could not handle command: {cmd}") + } + } + } }