use nom::{ bytes::complete::tag, character::complete::{char, multispace0, multispace1}, IResult, }; use super::common::{parse_condition, parse_table_name}; use crate::syntax::RawQuerySyntax; pub fn parse_delete(input: &str) -> IResult<&str, RawQuerySyntax> { let (input, _) = tag("DELETE")(input)?; let (input, _) = multispace1(input)?; let (input, _) = tag("FROM")(input)?; let (input, _) = multispace1(input)?; let (input, table_name) = parse_table_name(input)?; let (input, _) = multispace0(input)?; let (input, condition) = parse_condition(input)?; let (input, _) = multispace0(input)?; let (input, _) = char(';')(input)?; Ok(( input, RawQuerySyntax::Delete(table_name.to_string(), condition), )) } #[cfg(test)] mod tests { use crate::parsing::delete::parse_delete; use crate::syntax::RawQuerySyntax; #[test] fn test_parse_delete() { let (_, operation) = parse_delete("DELETE FROM \"T1\" WHERE id = 1 ;").expect("should parse"); assert!(matches!(operation, RawQuerySyntax::Delete(_, _))) } // TODO: add test with condition }