Use RawQuerySyntax for parsing
This commit is contained in:
parent
562e732138
commit
9771a89716
10 changed files with 65 additions and 62 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use super::common::{parse_table_name, parse_column_name, parse_condition};
|
||||
use minisql::operation::{ColumnSelection, Operation};
|
||||
use crate::syntax::{ColumnSelection, RawQuerySyntax};
|
||||
use nom::{
|
||||
branch::alt,
|
||||
bytes::complete::tag,
|
||||
|
|
@ -11,7 +11,7 @@ use nom::{
|
|||
IResult,
|
||||
};
|
||||
|
||||
pub fn parse_select(input: &str) -> IResult<&str, Operation> {
|
||||
pub fn parse_select(input: &str) -> IResult<&str, RawQuerySyntax> {
|
||||
let (input, _) = tag("SELECT")(input)?;
|
||||
let (input, _) = multispace1(input)?;
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ pub fn parse_select(input: &str) -> IResult<&str, Operation> {
|
|||
let (input, _) = tag(";")(input)?;
|
||||
Ok((
|
||||
input,
|
||||
Operation::Select(table_name.to_string(), column_selection, condition),
|
||||
RawQuerySyntax::Select(table_name.to_string(), column_selection, condition),
|
||||
))
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ pub fn try_parse_column_selection(input: &str) -> IResult<&str, ColumnSelection>
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use minisql::operation::{ColumnSelection, Operation};
|
||||
use crate::syntax::{ColumnSelection, RawQuerySyntax};
|
||||
use crate::parsing::{common::{parse_column_name, parse_table_name}, select::parse_select};
|
||||
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ mod tests {
|
|||
let sql = "SELECT * FROM \"MyTable\";";
|
||||
let operation = parse_select(sql).expect("should parse");
|
||||
match operation {
|
||||
("", Operation::Select(table_name, column_selection, maybe_condition)) => {
|
||||
("", RawQuerySyntax::Select(table_name, column_selection, maybe_condition)) => {
|
||||
assert_eq!(table_name, "MyTable");
|
||||
assert!(matches!(column_selection, ColumnSelection::All));
|
||||
assert!(matches!(maybe_condition, None));
|
||||
|
|
@ -80,7 +80,7 @@ mod tests {
|
|||
let sql = "SELECT name , email FROM \"AddressBook\" ;";
|
||||
let operation = parse_select(sql).expect("should parse");
|
||||
match operation {
|
||||
("", Operation::Select(table_name, column_selection, maybe_condition)) => {
|
||||
("", RawQuerySyntax::Select(table_name, column_selection, maybe_condition)) => {
|
||||
assert_eq!(table_name, "AddressBook");
|
||||
assert!(matches!(column_selection, ColumnSelection::Columns(_)));
|
||||
match column_selection {
|
||||
|
|
@ -102,11 +102,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_parse_select_where() {
|
||||
use minisql::operation::Condition;
|
||||
use crate::syntax::Condition;
|
||||
let sql = "SELECT * FROM \"AddressBook\" WHERE id = 5 ;";
|
||||
let operation = parse_select(sql).expect("should parse");
|
||||
match operation {
|
||||
("", Operation::Select(table_name, column_selection, maybe_condition)) => {
|
||||
("", RawQuerySyntax::Select(table_name, column_selection, maybe_condition)) => {
|
||||
assert_eq!(table_name, "AddressBook");
|
||||
assert!(matches!(column_selection, ColumnSelection::All));
|
||||
assert!(matches!(maybe_condition, Some(Condition::Eq(_, _))));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue