Skip to content

Commit 44acd75

Browse files
committed
A skeleton for module 'Queries' was implemented
1 parent ce66f0d commit 44acd75

15 files changed

+162
-128
lines changed

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ use crate::main_module::model::data::data_object::DataObject;
2727
pub mod main_module;
2828

2929
fn main() {
30-
let new_obj = DataObject::new("name", "Oleg");
31-
println!("{:?}", new_obj);
30+
let new_obj = DataObject::new("name", "Oleg");
31+
println!("{:?}", new_obj);
3232
}

src/main_module/controller/create_table_handler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
use crate::main_module::model::data::data_handler::DataHandler;
2626

2727
pub struct CreateTableHandler {
28-
data_handler: DataHandler,
28+
data_handler: DataHandler,
2929
}
3030

3131
impl CreateTableHandler {
32-
pub fn new() -> Self {
33-
let data_handler = DataHandler::new();
32+
pub fn new() -> Self {
33+
let data_handler = DataHandler::new();
3434

35-
CreateTableHandler { data_handler }
36-
}
35+
CreateTableHandler { data_handler }
36+
}
3737
}

src/main_module/model/data/data_handler.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@
2222
* SOFTWARE.
2323
*/
2424

25-
use std::collections::HashMap;
25+
use std::collections::{HashMap, HashSet};
2626

2727
use crate::main_module::model::data::table::Table;
2828

2929
pub struct DataHandler {
30-
tables: HashMap<String, Table>,
30+
tables: HashMap<String, Table>,
3131
}
3232

3333
impl DataHandler {
34-
pub fn new() -> Self {
35-
DataHandler {
36-
tables: HashMap::new(),
37-
}
38-
}
34+
pub fn new() -> Self {
35+
DataHandler {
36+
tables: HashMap::new(),
37+
}
38+
}
3939

40-
pub fn create_new_table() {
41-
todo!()
42-
}
40+
pub fn create_new_table(str: &str, set: HashSet<String>) {
41+
todo!()
42+
}
4343

44-
pub fn insert_into_table() {
45-
todo!()
46-
}
44+
pub fn insert_into_table() {
45+
todo!()
46+
}
4747
}

src/main_module/model/data/data_object.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
#[derive(Debug)]
2626
pub struct DataObject {
27-
field_name: String,
28-
value: String,
27+
field_name: String,
28+
value: String,
2929
}
3030

3131
impl DataObject {
32-
pub fn new(field_name: &str, field_value: &str) -> Self {
33-
DataObject {
34-
field_name: String::from(field_name),
35-
value: String::from(field_value),
36-
}
37-
}
32+
pub fn new(field_name: &str, field_value: &str) -> Self {
33+
DataObject {
34+
field_name: String::from(field_name),
35+
value: String::from(field_value),
36+
}
37+
}
3838
}

src/main_module/model/data/table.rs

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -27,74 +27,73 @@ use std::collections::{HashMap, HashSet};
2727
use crate::main_module::model::data::data_object::DataObject;
2828

2929
pub struct Table {
30-
error_id: String,
31-
error_arg: String,
32-
error_rws: String,
33-
column_names: HashSet<String>,
34-
rows: HashMap<String, Vec<DataObject>>,
30+
error_id: String,
31+
error_arg: String,
32+
error_rws: String,
33+
column_names: HashSet<String>,
34+
rows: HashMap<String, Vec<DataObject>>,
3535
}
3636

3737
impl Table {
38-
pub fn new() -> Self {
39-
Table {
40-
error_id: String::from("[ERROR] [Incorrect ID]"),
41-
error_arg: String::from("[ERROR] [Incorrect rows in insert data package"),
42-
error_rws: String::from("[ERROR] [Trying to reach an empty row]"),
43-
column_names: HashSet::new(),
44-
rows: HashMap::new(),
45-
}
46-
}
47-
48-
//TODO: implement all these functions
49-
fn generate_unique_id() {
50-
todo!()
51-
}
52-
53-
fn verify_id() {
54-
todo!()
55-
}
56-
57-
fn verify_field() {
58-
todo!()
59-
}
60-
61-
fn verify_rows() {
62-
todo!()
63-
}
64-
65-
fn verify_column_names_correct() {
66-
todo!()
67-
}
68-
69-
fn verify_id_and_field() {
70-
todo!()
71-
}
72-
73-
fn verify_id_and_columns() {
74-
todo!()
75-
}
76-
77-
pub fn row_is_empty() {
78-
todo!()
79-
}
80-
81-
pub fn get_field_value() {
82-
todo!()
83-
}
84-
85-
pub fn add_row() {
86-
todo!()
87-
}
88-
89-
pub fn return_row() {
90-
todo!()
91-
}
92-
93-
pub fn remove_row() {
94-
todo!()
95-
}
96-
97-
pub fn update_row_field_values() {
98-
todo!()
99-
}
38+
pub fn new() -> Self {
39+
Table {
40+
error_id: String::from("[ERROR] [Incorrect ID]"),
41+
error_arg: String::from("[ERROR] [Incorrect rows in insert data package"),
42+
error_rws: String::from("[ERROR] [Trying to reach an empty row]"),
43+
column_names: HashSet::new(),
44+
rows: HashMap::new(),
45+
}
46+
}
47+
48+
fn generate_unique_id() {
49+
todo!()
50+
}
51+
52+
fn verify_id() {
53+
todo!()
54+
}
55+
56+
fn verify_field() {
57+
todo!()
58+
}
59+
60+
fn verify_rows() {
61+
todo!()
62+
}
63+
64+
fn verify_column_names_correct() {
65+
todo!()
66+
}
67+
68+
fn verify_id_and_field() {
69+
todo!()
70+
}
71+
72+
fn verify_id_and_columns() {
73+
todo!()
74+
}
75+
76+
pub fn row_is_empty() {
77+
todo!()
78+
}
79+
80+
pub fn get_field_value() {
81+
todo!()
82+
}
83+
84+
pub fn add_row() {
85+
todo!()
86+
}
87+
88+
pub fn return_row() {
89+
todo!()
90+
}
91+
92+
pub fn remove_row() {
93+
todo!()
94+
}
95+
96+
pub fn update_row_field_values() {
97+
todo!()
98+
}
10099
}

src/main_module/model/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24+
2425
pub mod data;
25-
pub mod queries;
26+
pub mod queries;

src/main_module/model/queries/commands/abstract_command.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main_module/model/queries/commands/create_table_command.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,27 @@
2020
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
23-
*/
23+
*/
24+
25+
use std::collections::HashSet;
26+
27+
use crate::main_module::model::data::data_handler::DataHandler;
28+
use crate::main_module::model::queries::commands::querry_command::QueryCommand;
29+
30+
pub struct CreateTableCommand {}
31+
32+
impl QueryCommand for CreateTableCommand {
33+
fn execute_command(command_line: String) {
34+
let binding = command_line.replace("\\);", "");
35+
let binding = binding.split(" \\(");
36+
let mut command_addr = binding;
37+
38+
let table_name = command_addr.next().unwrap();
39+
let column_name = command_addr.next().unwrap();
40+
let mut column_names: HashSet<String> = HashSet::new();
41+
column_names.insert(column_name.to_string());
42+
let temp: HashSet<String> = HashSet::new();
43+
44+
DataHandler::create_new_table(table_name, temp);
45+
}
46+
}

src/main_module/model/queries/commands/insert_into_command.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@
2020
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
23-
*/
23+
*/
24+
25+
use crate::main_module::model::queries::commands::querry_command::QueryCommand;
26+
27+
pub struct InsertIntoCommand {}
28+
29+
impl QueryCommand for InsertIntoCommand {
30+
fn execute_command(command_line: String) {
31+
todo!()
32+
}
33+
}

src/main_module/model/queries/commands/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
pub mod abstract_command;
24+
2525
pub mod create_table_command;
2626
pub mod insert_into_command;
27-
pub mod querry_command;
27+
pub mod querry_command;

0 commit comments

Comments
 (0)