diff --git a/Plugins/Alice-Database/Cargo.toml b/Plugins/Alice-Database/Cargo.toml index 74b5e6a..20b6549 100644 --- a/Plugins/Alice-Database/Cargo.toml +++ b/Plugins/Alice-Database/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "Alice-Database_DBMS" -version = "1.2.3" +name = "AliceDBMS" +version = "1.2.8" edition = "2021" include = ["**/*.rs", "Cargo.toml","proto/*.proto", "src/syntax/*.pest", "src/test.decl"] license = "MIT" diff --git a/Plugins/Alice-Database/README.md b/Plugins/Alice-Database/README.md index f95d319..5c5e911 100644 --- a/Plugins/Alice-Database/README.md +++ b/Plugins/Alice-Database/README.md @@ -30,7 +30,7 @@ To set up Alice DBMS, ensure you have Rust and Cargo installed. You can then add ```toml [dependencies] -Alice-Database_DBMS = "=0.1.0" +AliceDBMS = "^1.2.7" ``` Then, run: @@ -44,22 +44,11 @@ cargo build Here's a brief example of how to use the Alice DBMS module: ```rust +use AliceDBMS::prelude::*; + fn main() -> std::io::Result<()> { - // Define the root path for data storage - let root_path = Path::new("path_to_your_database"); - let mut manager = CollectionManager::new(&root_path); - - // Add a new collection - manager.add_collection("example_collection").unwrap(); - - // Prepare document content - let doc_content = json!({"key": "value"}).to_string(); - - // Add a new document to the collection - manager.get_collection_mut("example_collection").unwrap() - .add_document("example_doc.json", &doc_content).unwrap(); - - println!("Document added successfully!"); + let mut instance_manager = InstanceManager::new(&get_root_path()); + cli(&mut instance_manager); Ok(()) } ``` diff --git a/Plugins/Alice-Database/build.rs b/Plugins/Alice-Database/build.rs index 163bdbd..c68ef4b 100644 --- a/Plugins/Alice-Database/build.rs +++ b/Plugins/Alice-Database/build.rs @@ -1,3 +1,24 @@ +/* MIT License + +Copyright (c) 2024 Daniil Ermolaev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +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. */ fn main() { tonic_build::compile_protos("proto/instance.proto").unwrap(); diff --git a/Plugins/Alice-Database/src/cli.rs b/Plugins/Alice-Database/src/cli.rs index 0fad280..9afc9b9 100644 --- a/Plugins/Alice-Database/src/cli.rs +++ b/Plugins/Alice-Database/src/cli.rs @@ -1,9 +1,31 @@ -use std::io::{self, Write}; +/* MIT License + +Copyright (c) 2024 Daniil Ermolaev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +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::io::{ self, Write }; use crate::instance::*; pub fn cli(instance_manager: &mut InstanceManager) { loop { - print!("[ Instance Manager ] (type 'exit' to quit)=: "); + print!("[ INSTANCE MANAGER ] (type 'exit' to quit)=: "); io::stdout().flush().unwrap(); let mut input = String::new(); diff --git a/Plugins/Alice-Database/src/engines.rs b/Plugins/Alice-Database/src/engines.rs index 807ebbe..091dac9 100644 --- a/Plugins/Alice-Database/src/engines.rs +++ b/Plugins/Alice-Database/src/engines.rs @@ -23,8 +23,12 @@ SOFTWARE. */ use crate::json_engine::JSONEngine; use crate::log_engine::LOGEngine; +use std::fmt; + #[derive(Debug, Clone)] pub enum Engines { LOGEngine(LOGEngine), JSONEngine(JSONEngine), } + + diff --git a/Plugins/Alice-Database/src/instance.rs b/Plugins/Alice-Database/src/instance.rs index 06db191..92998c1 100644 --- a/Plugins/Alice-Database/src/instance.rs +++ b/Plugins/Alice-Database/src/instance.rs @@ -20,17 +20,20 @@ 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::Engines; +use crate::engines::Engines; use uuid::Uuid; use std::path::{PathBuf, Path}; use std::fs::File; use std::io::{self, BufRead}; -use crate::{JSONEngine, LOGEngine}; + +use crate::json_engine::JSONEngine; +use crate::log_engine::LOGEngine; + use std::collections::HashMap; -use crate::IMPestParser; +use crate::command_executor::IMPestParser; use pest_derive::Parser; use pest::Parser; -use crate::Rule; +use crate::command_executor::Rule; macro_rules! adbprint { ($($arg:tt)*) => { @@ -122,6 +125,9 @@ impl InstanceManager { Rule::print_addbms => { adbprint!("{:#?}", self); }, + Rule::supported_engines => { + adbprint!("LOGEngine (log_engine)\nJSONEngine (json_engine)"); + }, Rule::create_collection => { let inner = inner_pair.into_inner().as_str().split(" INSTANCE WITH NAME ").collect::>(); if let Some(engine) = self.get_mutable_engine(inner[0]) { @@ -183,16 +189,23 @@ impl InstanceManager { self.execute_cmd(command) .map_err(|e| { adbprint!("Error! {}", e); e }) } - pub fn execute_decl_file

(&mut self, filename: P) -> Result<(), io::Error> where - P: AsRef, + P: AsRef, { let file = File::open(filename)?; let reader = io::BufReader::new(file); for line in reader.lines() { - if let Err(e) = self.wrapped_execute_cmd(&line?.replace("\n", "")) { + let line = line?; + + // Check if the line starts with '#', continue if it does + if line.trim_start().starts_with('#') { + continue; // Skip this line + } + + // Execute the command after removing newline characters + if let Err(e) = self.wrapped_execute_cmd(&line.replace("\n", "")) { adbprint!("Failed to execute line: {}", e); } } diff --git a/Plugins/Alice-Database/src/json_engine.rs b/Plugins/Alice-Database/src/json_engine.rs index 5397822..5beb876 100644 --- a/Plugins/Alice-Database/src/json_engine.rs +++ b/Plugins/Alice-Database/src/json_engine.rs @@ -24,6 +24,7 @@ use std::fs; use std::io::{self, Read, Write}; use std::env; use std::path::{PathBuf, Path}; + use serde_json::{json, Value, Result as JsonResult}; use log::{info, error, trace}; diff --git a/Plugins/Alice-Database/src/lib.rs b/Plugins/Alice-Database/src/lib.rs new file mode 100644 index 0000000..c8ab482 --- /dev/null +++ b/Plugins/Alice-Database/src/lib.rs @@ -0,0 +1,12 @@ +pub mod json_engine; +pub mod log_engine; + +pub mod engines; + +pub mod grpc_server; +pub mod instance; +pub mod utils; +pub mod command_executor; +pub mod cli; + +pub mod prelude; diff --git a/Plugins/Alice-Database/src/log_engine.rs b/Plugins/Alice-Database/src/log_engine.rs index 4d0c629..6252617 100644 --- a/Plugins/Alice-Database/src/log_engine.rs +++ b/Plugins/Alice-Database/src/log_engine.rs @@ -1,3 +1,26 @@ +/* MIT License + +Copyright (c) 2024 Daniil Ermolaev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +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. */ + +// I want to replace this code to universal file. use std::fs::*; use std::io::{self, Read, Write}; diff --git a/Plugins/Alice-Database/src/main.rs b/Plugins/Alice-Database/src/main.rs index 53975cb..3e901f8 100644 --- a/Plugins/Alice-Database/src/main.rs +++ b/Plugins/Alice-Database/src/main.rs @@ -1,4 +1,3 @@ - /* MIT License Copyright (c) 2024 Daniil Ermolaev @@ -21,18 +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. */ -use std::{ env, fs }; -use std::io::{ self, Read, Write }; -use std::path::{ PathBuf, Path }; -use std::sync::{ Arc, Mutex }; - -use serde_json::{ json, Value, Result as JsonResult }; - -use log::{ info, error, trace }; -use simplelog::*; - -use chrono::Local; - pub mod json_engine; pub mod log_engine; pub mod engines; @@ -42,14 +29,9 @@ pub mod utils; pub mod command_executor; pub mod cli; -use json_engine::*; -use log_engine::*; -use engines::*; -use grpc_server::*; -use instance::*; -use utils::*; -use command_executor::*; -use cli::cli; +pub mod prelude; +use prelude::*; + /* gRPC #[tokio::main] async fn main() -> Result<(), Box> { @@ -73,7 +55,6 @@ async fn main() -> Result<(), Box> { #[tokio::main] async fn main() -> Result<(), Box> { let root_path: PathBuf = get_root_path(); - let mut im = InstanceManager::new(&root_path); //let k = im.execute_decl_file(Path::new("./test.decl")); cli(&mut im); diff --git a/Plugins/Alice-Database/src/prelude.rs b/Plugins/Alice-Database/src/prelude.rs new file mode 100644 index 0000000..8b9f994 --- /dev/null +++ b/Plugins/Alice-Database/src/prelude.rs @@ -0,0 +1,63 @@ +/* MIT License + +Copyright (c) 2024 Daniil Ermolaev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +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 use std::{ env, fs, fmt }; +pub use std::io::{ self, Read, Write, BufRead }; +pub use std::path::{ PathBuf, Path }; +pub use std::sync::{ Arc, Mutex }; + +pub use pest_derive::Parser; +pub use pest::Parser; + +pub use serde_json::{ json, Value, Result as JsonResult }; + +pub use log::{ info, error, trace }; +pub use simplelog::*; + +pub use chrono::Local; + +/* +pub mod json_engine; +pub mod log_engine; +pub mod engines; +pub mod grpc_server; +pub mod instance; +pub mod utils; +pub mod command_executor; +pub mod cli; +*/ + +pub use crate::json_engine::*; +pub use crate::log_engine::*; + +pub use crate::engines::*; +pub use crate::grpc_server::*; +pub use crate::instance::*; +pub use crate::utils::*; +pub use crate::command_executor::*; +pub use crate::cli::cli; + +pub use tonic::{ transport::Server, Request, Response, Status }; + +pub use uuid::Uuid; +pub use std::collections::HashMap; + diff --git a/Plugins/Alice-Database/src/syntax/instance_manager.pest b/Plugins/Alice-Database/src/syntax/instance_manager.pest index 581f9e0..710d546 100644 --- a/Plugins/Alice-Database/src/syntax/instance_manager.pest +++ b/Plugins/Alice-Database/src/syntax/instance_manager.pest @@ -14,9 +14,12 @@ print_addbms = { "PRINTALLDDBMS" } create_collection = { "CREATE COLLECTION IN " ~ ident ~ " INSTANCE WITH NAME " ~ ident } create_document = { "CREATE DOCUMENT IN " ~ ident ~ " INSTANCE IN COLLECTION " ~ ident ~ " WITH NAME " ~ ident} +supported_engines = { "GET SUPPORTED ENGINES" } + + sql_statement = { create_instance | get_instance | get_instances | delete_instance | print_addbms | - create_collection | create_document + create_collection | create_document | supported_engines } sql_statements = _{ sql_statement ~ ((";" ~ sql_statement) | (";" ~ sql_statement))* ~ ";"? }