From ea4e53d15f70e9aae77a1ee56f3ae94ec457b526 Mon Sep 17 00:00:00 2001 From: myyrakle Date: Tue, 19 Mar 2024 00:53:41 +0900 Subject: [PATCH] =?UTF-8?q?[#69]=20commit=20=ED=8C=8C=EC=8B=B1=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ast/tcl/commit.rs | 8 ++++ src/parser/implements/tcl/commit.rs | 14 +++++++ src/parser/implements/tcl/mod.rs | 1 + src/parser/parser.rs | 4 ++ src/parser/test/mod.rs | 2 +- .../test/{begin_transaction.rs => tcl.rs} | 40 ++++++++++++++++++- 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/parser/implements/tcl/commit.rs rename src/parser/test/{begin_transaction.rs => tcl.rs} (60%) diff --git a/src/ast/tcl/commit.rs b/src/ast/tcl/commit.rs index e7186dc1..281ea422 100644 --- a/src/ast/tcl/commit.rs +++ b/src/ast/tcl/commit.rs @@ -1,2 +1,10 @@ +use crate::ast::{SQLStatement, TCLStatement}; + #[derive(Clone, Debug, PartialEq, Eq)] pub struct CommitQuery {} + +impl From for SQLStatement { + fn from(value: CommitQuery) -> SQLStatement { + SQLStatement::TCL(TCLStatement::Commit(value)) + } +} diff --git a/src/parser/implements/tcl/commit.rs b/src/parser/implements/tcl/commit.rs new file mode 100644 index 00000000..e821578d --- /dev/null +++ b/src/parser/implements/tcl/commit.rs @@ -0,0 +1,14 @@ +use std::error::Error; + +use crate::ast::tcl::CommitQuery; +use crate::ast::SQLStatement; +use crate::parser::predule::{Parser, ParserContext}; + +impl Parser { + pub(crate) fn parse_commit_query( + &mut self, + _context: ParserContext, + ) -> Result> { + Ok(CommitQuery {}.into()) + } +} diff --git a/src/parser/implements/tcl/mod.rs b/src/parser/implements/tcl/mod.rs index 8d27fcce..bdfe18f0 100644 --- a/src/parser/implements/tcl/mod.rs +++ b/src/parser/implements/tcl/mod.rs @@ -1 +1,2 @@ pub mod begin; +pub mod commit; diff --git a/src/parser/parser.rs b/src/parser/parser.rs index f432d2cd..3434bccc 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -90,6 +90,10 @@ impl Parser { let query = self.parse_begin_query(context.clone())?; statements.push(query); } + Token::Commit => { + let query = self.parse_commit_query(context.clone())?; + statements.push(query); + } _ => { break; } diff --git a/src/parser/test/mod.rs b/src/parser/test/mod.rs index 7a0a3769..3111f8f3 100644 --- a/src/parser/test/mod.rs +++ b/src/parser/test/mod.rs @@ -14,4 +14,4 @@ pub(crate) mod update; pub(crate) mod other; -pub(crate) mod begin_transaction; +pub(crate) mod tcl; diff --git a/src/parser/test/begin_transaction.rs b/src/parser/test/tcl.rs similarity index 60% rename from src/parser/test/begin_transaction.rs rename to src/parser/test/tcl.rs index 0067accb..23734b4e 100644 --- a/src/parser/test/begin_transaction.rs +++ b/src/parser/test/tcl.rs @@ -1,7 +1,10 @@ #![cfg(test)] use crate::{ - ast::{tcl::BeginTransactionQuery, SQLStatement}, + ast::{ + tcl::{BeginTransactionQuery, CommitQuery}, + SQLStatement, + }, parser::predule::{Parser, ParserContext}, }; @@ -53,3 +56,38 @@ pub fn begin_transaction() { assert_eq!(result.unwrap(), vec![tc.expected], "{}", tc.name); } } + +#[test] +pub fn commit() { + struct TestCase { + name: String, + input: String, + expected: SQLStatement, + want_err: bool, + } + + let test_cases = vec![TestCase { + name: "정상적인 Commit 명령".to_owned(), + input: "COMMIT;".to_owned(), + expected: CommitQuery {}.into(), + want_err: false, + }]; + + for tc in test_cases { + let mut parser = Parser::new(tc.input).unwrap(); + + let result = parser.parse(ParserContext::default()); + + if tc.want_err { + assert!( + result.is_err(), + "{} - expected error, got {:?}", + tc.name, + result + ); + continue; + } + + assert_eq!(result.unwrap(), vec![tc.expected], "{}", tc.name); + } +}