Skip to content

A skeleton for module 'Queries' was implemented #7

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

Merged
merged 1 commit into from
May 28, 2023
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: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ use crate::main_module::model::data::data_object::DataObject;
pub mod main_module;

fn main() {
let new_obj = DataObject::new("name", "Oleg");
println!("{:?}", new_obj);
let new_obj = DataObject::new("name", "Oleg");
println!("{:?}", new_obj);
}
10 changes: 5 additions & 5 deletions src/main_module/controller/create_table_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
use crate::main_module::model::data::data_handler::DataHandler;

pub struct CreateTableHandler {
data_handler: DataHandler,
data_handler: DataHandler,
}

impl CreateTableHandler {
pub fn new() -> Self {
let data_handler = DataHandler::new();
pub fn new() -> Self {
let data_handler = DataHandler::new();

CreateTableHandler { data_handler }
}
CreateTableHandler { data_handler }
}
}
26 changes: 13 additions & 13 deletions src/main_module/model/data/data_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@
* SOFTWARE.
*/

use std::collections::HashMap;
use std::collections::{HashMap, HashSet};

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

pub struct DataHandler {
tables: HashMap<String, Table>,
tables: HashMap<String, Table>,
}

impl DataHandler {
pub fn new() -> Self {
DataHandler {
tables: HashMap::new(),
}
}
pub fn new() -> Self {
DataHandler {
tables: HashMap::new(),
}
}

pub fn create_new_table() {
todo!()
}
pub fn create_new_table(str: &str, set: HashSet<String>) {
todo!()
}

pub fn insert_into_table() {
todo!()
}
pub fn insert_into_table() {
todo!()
}
}
16 changes: 8 additions & 8 deletions src/main_module/model/data/data_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@

#[derive(Debug)]
pub struct DataObject {
field_name: String,
value: String,
field_name: String,
value: String,
}

impl DataObject {
pub fn new(field_name: &str, field_value: &str) -> Self {
DataObject {
field_name: String::from(field_name),
value: String::from(field_value),
}
}
pub fn new(field_name: &str, field_value: &str) -> Self {
DataObject {
field_name: String::from(field_name),
value: String::from(field_value),
}
}
}
133 changes: 66 additions & 67 deletions src/main_module/model/data/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,74 +27,73 @@ use std::collections::{HashMap, HashSet};
use crate::main_module::model::data::data_object::DataObject;

pub struct Table {
error_id: String,
error_arg: String,
error_rws: String,
column_names: HashSet<String>,
rows: HashMap<String, Vec<DataObject>>,
error_id: String,
error_arg: String,
error_rws: String,
column_names: HashSet<String>,
rows: HashMap<String, Vec<DataObject>>,
}

impl Table {
pub fn new() -> Self {
Table {
error_id: String::from("[ERROR] [Incorrect ID]"),
error_arg: String::from("[ERROR] [Incorrect rows in insert data package"),
error_rws: String::from("[ERROR] [Trying to reach an empty row]"),
column_names: HashSet::new(),
rows: HashMap::new(),
}
}

//TODO: implement all these functions
fn generate_unique_id() {
todo!()
}

fn verify_id() {
todo!()
}

fn verify_field() {
todo!()
}

fn verify_rows() {
todo!()
}

fn verify_column_names_correct() {
todo!()
}

fn verify_id_and_field() {
todo!()
}

fn verify_id_and_columns() {
todo!()
}

pub fn row_is_empty() {
todo!()
}

pub fn get_field_value() {
todo!()
}

pub fn add_row() {
todo!()
}

pub fn return_row() {
todo!()
}

pub fn remove_row() {
todo!()
}

pub fn update_row_field_values() {
todo!()
}
pub fn new() -> Self {
Table {
error_id: String::from("[ERROR] [Incorrect ID]"),
error_arg: String::from("[ERROR] [Incorrect rows in insert data package"),
error_rws: String::from("[ERROR] [Trying to reach an empty row]"),
column_names: HashSet::new(),
rows: HashMap::new(),
}
}

fn generate_unique_id() {
todo!()
}

fn verify_id() {
todo!()
}

fn verify_field() {
todo!()
}

fn verify_rows() {
todo!()
}

fn verify_column_names_correct() {
todo!()
}

fn verify_id_and_field() {
todo!()
}

fn verify_id_and_columns() {
todo!()
}

pub fn row_is_empty() {
todo!()
}

pub fn get_field_value() {
todo!()
}

pub fn add_row() {
todo!()
}

pub fn return_row() {
todo!()
}

pub fn remove_row() {
todo!()
}

pub fn update_row_field_values() {
todo!()
}
}
3 changes: 2 additions & 1 deletion src/main_module/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

pub mod data;
pub mod queries;
pub mod queries;
23 changes: 0 additions & 23 deletions src/main_module/model/queries/commands/abstract_command.rs

This file was deleted.

25 changes: 24 additions & 1 deletion src/main_module/model/queries/commands/create_table_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,27 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
*/

use std::collections::HashSet;

use crate::main_module::model::data::data_handler::DataHandler;
use crate::main_module::model::queries::commands::querry_command::QueryCommand;

pub struct CreateTableCommand {}

impl QueryCommand for CreateTableCommand {
fn execute_command(command_line: String) {
let binding = command_line.replace("\\);", "");
let binding = binding.split(" \\(");
let mut command_addr = binding;

let table_name = command_addr.next().unwrap();
let column_name = command_addr.next().unwrap();
let mut column_names: HashSet<String> = HashSet::new();
column_names.insert(column_name.to_string());
let temp: HashSet<String> = HashSet::new();

DataHandler::create_new_table(table_name, temp);
}
}
12 changes: 11 additions & 1 deletion src/main_module/model/queries/commands/insert_into_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
*/

use crate::main_module::model::queries::commands::querry_command::QueryCommand;

pub struct InsertIntoCommand {}

impl QueryCommand for InsertIntoCommand {
fn execute_command(command_line: String) {
todo!()
}
}
4 changes: 2 additions & 2 deletions src/main_module/model/queries/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
pub mod abstract_command;

pub mod create_table_command;
pub mod insert_into_command;
pub mod querry_command;
pub mod querry_command;
6 changes: 5 additions & 1 deletion src/main_module/model/queries/commands/querry_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
*/

pub trait QueryCommand {
fn execute_command(command_line: String);
}
8 changes: 7 additions & 1 deletion src/main_module/model/queries/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
*/

use crate::main_module::model::queries::query_element::QueryElement;

pub struct Query {
query_elements: Vec<QueryElement>,
}
6 changes: 5 additions & 1 deletion src/main_module/model/queries/query_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
*/

pub struct QueryElement {
query_composition: Vec<QueryElement>,
}
4 changes: 3 additions & 1 deletion src/main_module/model/queries/query_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
*/

pub struct QueryEntity {}
10 changes: 9 additions & 1 deletion src/main_module/model/queries/query_keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
*/

pub enum QueryKeyword {
CREATE_TABLE,
SELECT,
UPDATE,
DELETE,
INSERT_INTO,
}