Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#68] AST 디렉터리 구조 리팩터링 & AST에 TCL 추가 #70

Merged
merged 3 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ Cargo.lock

/target

.rrdb.config
.rrdb.config

.vscode
Binary file added rrdb/database.config
Binary file not shown.
2 changes: 1 addition & 1 deletion src/ast/ddl/alter_database.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{DDLStatement, SQLStatement};
use crate::ast::{DDLStatement, SQLStatement};

/*
ALTER DATABASE database_name
Expand Down
5 changes: 4 additions & 1 deletion src/ast/ddl/alter_table.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//use crate::ast::enums::SQLStatement;
use crate::ast::predule::{Column, DataType, SQLExpression, SQLStatement, TableName};
use crate::ast::{
types::{Column, DataType, SQLExpression, TableName},
SQLStatement,
};

use super::drop_database::DDLStatement;

Expand Down
2 changes: 1 addition & 1 deletion src/ast/ddl/create_database.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use crate::ast::predule::{Column, DDLStatement, SQLStatement};
pub use crate::ast::{DDLStatement, SQLStatement};

/*
CREATE DATABASE [IF NOT EXISTS] database_name;
Expand Down
5 changes: 4 additions & 1 deletion src/ast/ddl/create_index.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::ast::predule::{Column, DDLStatement, SQLStatement, TableName};
use crate::ast::{
types::{Column, TableName},
DDLStatement, SQLStatement,
};

/*
CREATE [ UNIQUE ] INDEX [ IF NOT EXISTS ] name ON table_name
Expand Down
5 changes: 3 additions & 2 deletions src/ast/ddl/create_table.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::ast::predule::{
Column, DDLStatement, ForeignKey, SQLStatement, TableName, TableOptions, UniqueKey,
use crate::ast::{
types::{Column, ForeignKey, TableName, TableOptions, UniqueKey},
DDLStatement, SQLStatement,
};

/*
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ddl/drop_database.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use crate::ast::predule::{Column, DDLStatement, SQLStatement};
pub use crate::ast::{DDLStatement, SQLStatement};

/*
DROP DATABASE [IF EXISTS] database_name;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ddl/drop_table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{DDLStatement, SQLStatement, TableName};
use crate::ast::{types::TableName, DDLStatement, SQLStatement};

/*
DROP TABLE [IF EXISTS] [database_name.]table_name;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/delete.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{DMLStatement, SQLStatement, TableName};
use crate::ast::{types::TableName, DMLStatement, SQLStatement};

use super::parts::{_where::WhereClause, target::UpdateTarget};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/expressions/between.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::Not;

use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;
use serde::{Deserialize, Serialize};

use super::not_between::NotBetweenExpression;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/expressions/binary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;
use serde::{Deserialize, Serialize};

use super::operators::BinaryOperator;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/expressions/call.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{Function, SQLExpression};
use crate::ast::types::{Function, SQLExpression};

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/expressions/list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/expressions/not_between.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/expressions/parentheses.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/expressions/subquery.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::{dml::select::SelectQuery, predule::SQLExpression};
use crate::ast::{dml::select::SelectQuery, types::SQLExpression};

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/expressions/unary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;
use serde::{Deserialize, Serialize};

use super::operators::UnaryOperator;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/insert.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{DMLStatement, SQLStatement, TableName};
use crate::ast::{types::TableName, DMLStatement, SQLStatement};

use super::{parts::insert_values::InsertValue, select::SelectQuery};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/parts/from.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::{dml::expressions::subquery::SubqueryExpression, predule::TableName};
use crate::ast::{dml::expressions::subquery::SubqueryExpression, types::TableName};

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/parts/group_by.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SelectColumn;
use crate::ast::types::SelectColumn;

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/parts/having.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/parts/insert_values.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;

#[derive(Clone, Debug, PartialEq)]
pub struct InsertValue {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/parts/join.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{SQLExpression, TableName};
use crate::ast::types::{SQLExpression, TableName};

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/parts/order_by.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/parts/select_item.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/parts/target.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::TableName;
use crate::ast::types::TableName;

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/parts/update_item.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;

#[derive(Clone, Debug, PartialEq)]
pub struct UpdateItem {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/parts/where.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/plan/delete/from.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::{dml::plan::select::scan::ScanType, predule::TableName};
use crate::ast::{dml::plan::select::scan::ScanType, types::TableName};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DeleteFromPlan {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/plan/select/filter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;

#[derive(Clone, Debug, PartialEq)]
pub struct FilterPlan {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/plan/select/from.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::TableName;
use crate::ast::types::TableName;

use super::scan::ScanType;

Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/plan/select/join.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::ast::{
dml::parts::join::JoinType,
predule::{Index, SQLExpression, TableName},
types::{Index, SQLExpression, TableName},
};

#[derive(Clone, Debug, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/plan/select/scan.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::Index;
use crate::ast::types::Index;

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ScanType {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/plan/select/subquery.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{Index, SQLExpression, TableName};
use crate::ast::types::{Index, SQLExpression, TableName};

#[derive(Clone, Debug, PartialEq)]
pub struct SelectSubqueryPlan {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/plan/update/from.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::{dml::plan::select::scan::ScanType, predule::TableName};
use crate::ast::{dml::plan::select::scan::ScanType, types::TableName};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct UpdateFromPlan {
Expand Down
3 changes: 2 additions & 1 deletion src/ast/dml/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use serde::{Deserialize, Serialize};

use crate::ast::{
ddl::drop_database::SQLStatement,
predule::{DMLStatement, SQLExpression, SelectColumn, TableName},
types::{SQLExpression, SelectColumn, TableName},
DMLStatement,
};

use super::{
Expand Down
2 changes: 1 addition & 1 deletion src/ast/dml/update.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{DMLStatement, SQLStatement, TableName};
use crate::ast::{types::TableName, DMLStatement, SQLStatement};

use super::parts::{_where::WhereClause, target::UpdateTarget, update_item::UpdateItem};

Expand Down
64 changes: 63 additions & 1 deletion src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,67 @@ pub mod dcl;
pub mod ddl;
pub mod dml;
pub mod other;
pub mod predule;
pub mod tcl;
pub mod types;

use crate::ast::{
ddl::{
alter_database::AlterDatabaseQuery, alter_table::AlterTableQuery,
create_database::CreateDatabaseQuery, create_index::CreateIndexQuery,
create_table::CreateTableQuery, drop_database::DropDatabaseQuery,
drop_table::DropTableQuery,
},
dml::{delete::DeleteQuery, insert::InsertQuery, select::SelectQuery, update::UpdateQuery},
other::{
desc_table::DescTableQuery, show_databases::ShowDatabasesQuery,
show_tables::ShowTablesQuery, use_database::UseDatabaseQuery,
},
};

use self::tcl::{BeginTransactionQuery, CommitQuery, RollbackQuery};

#[derive(Clone, Debug, PartialEq)]
pub enum SQLStatement {
DDL(DDLStatement),
DML(DMLStatement),
DCL(DCLStatement),
TCL(TCLStatement),
Other(OtherStatement),
}

#[derive(Clone, Debug, PartialEq)]
pub enum DDLStatement {
CreateDatabaseQuery(CreateDatabaseQuery),
AlterDatabase(AlterDatabaseQuery),
DropDatabaseQuery(DropDatabaseQuery),
CreateTableQuery(CreateTableQuery),
AlterTableQuery(AlterTableQuery),
DropTableQuery(DropTableQuery),
CreateIndexQuery(CreateIndexQuery),
}

#[derive(Clone, Debug, PartialEq)]
pub enum DMLStatement {
InsertQuery(InsertQuery),
UpdateQuery(UpdateQuery),
DeleteQuery(DeleteQuery),
SelectQuery(SelectQuery),
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum DCLStatement {}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum OtherStatement {
ShowDatabases(ShowDatabasesQuery),
UseDatabase(UseDatabaseQuery),
ShowTables(ShowTablesQuery),
DescTable(DescTableQuery),
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub enum TCLStatement {
BeginTransaction(BeginTransactionQuery),
Commit(CommitQuery),
Rollback(RollbackQuery),
}
2 changes: 1 addition & 1 deletion src/ast/other/desc_table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{OtherStatement, SQLStatement, TableName};
use crate::ast::{types::TableName, OtherStatement, SQLStatement};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DescTableQuery {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/other/show_databases.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{OtherStatement, SQLStatement};
use crate::ast::{OtherStatement, SQLStatement};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ShowDatabasesQuery {}
Expand Down
2 changes: 1 addition & 1 deletion src/ast/other/show_tables.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{OtherStatement, SQLStatement};
use crate::ast::{OtherStatement, SQLStatement};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ShowTablesQuery {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/other/use_database.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::{OtherStatement, SQLStatement};
use crate::ast::{OtherStatement, SQLStatement};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct UseDatabaseQuery {
Expand Down
7 changes: 0 additions & 7 deletions src/ast/predule.rs

This file was deleted.

2 changes: 2 additions & 0 deletions src/ast/tcl/begin_transaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BeginTransactionQuery {}
2 changes: 2 additions & 0 deletions src/ast/tcl/commit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CommitQuery {}
7 changes: 7 additions & 0 deletions src/ast/tcl/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod begin_transaction;
mod commit;
mod rollback;

pub use begin_transaction::*;
pub use commit::*;
pub use rollback::*;
2 changes: 2 additions & 0 deletions src/ast/tcl/rollback.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RollbackQuery {}
2 changes: 1 addition & 1 deletion src/ast/types/column.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::DataType;
use crate::ast::types::DataType;
use serde::{Deserialize, Serialize};

use super::expression::SQLExpression;
Expand Down
2 changes: 1 addition & 1 deletion src/ast/types/foreign_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::TableName;
use crate::ast::types::TableName;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
Expand Down
3 changes: 0 additions & 3 deletions src/ast/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ pub use select_column::*;
pub mod function;
pub use function::*;

pub mod statement;
pub use statement::*;

pub mod expression;
pub use expression::*;

Expand Down
2 changes: 1 addition & 1 deletion src/ast/types/select_column.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ast::predule::SQLExpression;
use crate::ast::types::SQLExpression;
use serde::{Deserialize, Serialize};

// [table_alias.]column_name
Expand Down
Loading
Loading