Skip to content

Commit

Permalink
New declarative
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBLCKLPTN committed Oct 26, 2024
1 parent 92501e2 commit f8f7c3d
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Plugins/Alice-Database/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "AliceDBMS"
version = "1.2.7"
version = "1.2.8"
edition = "2021"
include = ["**/*.rs", "Cargo.toml","proto/*.proto", "src/syntax/*.pest", "src/test.decl"]
license = "MIT"
Expand Down
21 changes: 5 additions & 16 deletions Plugins/Alice-Database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(())
}
```
Expand Down
21 changes: 21 additions & 0 deletions Plugins/Alice-Database/build.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
26 changes: 24 additions & 2 deletions Plugins/Alice-Database/src/cli.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
1 change: 1 addition & 0 deletions Plugins/Alice-Database/src/engines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SOFTWARE. */

use crate::json_engine::JSONEngine;
use crate::log_engine::LOGEngine;

use std::fmt;

#[derive(Debug, Clone)]
Expand Down
13 changes: 10 additions & 3 deletions Plugins/Alice-Database/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,23 @@ impl InstanceManager {
self.execute_cmd(command)
.map_err(|e| { adbprint!("Error! {}", e); e })
}

pub fn execute_decl_file<P>(&mut self, filename: P) -> Result<(), io::Error>
where
P: AsRef<Path>,
P: AsRef<Path>,
{
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);
}
}
Expand Down
1 change: 1 addition & 0 deletions Plugins/Alice-Database/src/json_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
1 change: 1 addition & 0 deletions Plugins/Alice-Database/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod json_engine;
pub mod log_engine;

pub mod engines;

pub mod grpc_server;
Expand Down
23 changes: 23 additions & 0 deletions Plugins/Alice-Database/src/log_engine.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
1 change: 0 additions & 1 deletion Plugins/Alice-Database/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/* MIT License
Copyright (c) 2024 Daniil Ermolaev
Expand Down
22 changes: 22 additions & 0 deletions Plugins/Alice-Database/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/* 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 };
Expand Down

0 comments on commit f8f7c3d

Please sign in to comment.