Skip to content

Commit

Permalink
Memore Database
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBLCKLPTN committed Oct 20, 2024
1 parent ea17f22 commit 0a18131
Show file tree
Hide file tree
Showing 32 changed files with 1,458 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Plugins/Alice-Database_v2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2021"

[features]
default = ["log_engine", "json_engine"]
default = ["log_engine"]
log_engine = []
json_engine = []
#json_engine = []

[dependencies]
aes = "0.8.4"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"0eb9cc86-9231-4f74-ae54-677167e22e06": [
"qwe",
123,
"twrtret"
],
"2348d1de-501f-4fba-8965-21c95820549b": {
"qwe": "qweqweqwe"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"0eb9cc86-9231-4f74-ae54-677167e22e06": [
"qwe",
123,
"twrtret"
],
"2348d1de-501f-4fba-8965-21c95820549b": {
"qwe": "qweqweqwe"
}
}
10 changes: 10 additions & 0 deletions Plugins/Alice-Database_v2/src/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"e363be5e-fdc8-4395-ad8f-cb455632eda8": [
"qwe",
123,
"twrtret"
],
"3abd7b2c-0fc4-46e4-a1eb-dc80b591f62c": {
"qwe": "qweqweqwe"
}
}
47 changes: 38 additions & 9 deletions Plugins/Alice-Database_v2/src/engines/json_engine.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,61 @@
use log::{info, warn, error};
use std::ffi::{CStr, CString};
use std::os::raw::c_char;
use std::collections::HashMap;

use serde_json::Value;
use serde_json::Map;

// Define the JSONEngine struct
#[derive(Debug, Clone)]
pub struct JSONEngine {
pub name: String,
pub data: Vec<String>,
pub data: Vec<Map<String, Value>>,
}

#[derive(Debug, Clone)]
pub struct Sort {
pub data: Vec<HashMap<String, Value>>,
}

impl JSONEngine {
pub fn new(name: String) -> Self {
let mut data: Vec<Map<String,Value>> = vec![];
info!("Creating JSON Engine...");
Self { name, data: Vec::new() }
Self { name, data }
}

pub fn insert_one(&mut self, new_data: Value) -> String {
self.data.push(new_data);
println!("SELF DATA: {:#?}", self.data);
}

pub fn insert_many(&mut self) -> Vec<String> {
todo!();
}

// Add data to the JSONEngine
pub fn add_data(&mut self, new_data: &str) {
info!("Adding data to JSON Engine...");
self.data.push(new_data.to_string());
pub fn find_one(&self) {
todo!();
}

// Retrieve all data (for simplicity, returning as a joined string)
pub fn get_data(&self) -> String {
self.data.join("\n")
pub fn find_all(&self) {
todo!();
}

pub fn find_with_filter(&self) {
todo!();
}

pub fn commit(&self) {
todo!();
}

}





// C bindings
#[no_mangle]
pub extern "C" fn json_engine_new(name: *const c_char) -> *mut JSONEngine {
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Alice-Database_v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use instance_manager::ADBInstanceManager;

use log::{ info, error };

/*

#[tokio::main]
async fn main() {
let mut instance_manager = match ADBInstanceManager::find_all().await {
Expand All @@ -29,4 +29,4 @@ async fn main() {
println!("Instance Manager: {:#?}", instance_manager);
println!("Hello World!");
}
*/

72 changes: 72 additions & 0 deletions Plugins/Alice-Database_v2/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
use serde_json::{json, Value};
use uuid::Uuid;

#[derive(Clone, Debug)]
pub struct JSONEngine {
pub name: String,
pub data: HashMap<String, Value>, // Изменили на HashMap
}

impl JSONEngine {
pub fn new(name: String) -> Self {
Self { name, data: HashMap::new() }
}

pub fn insert_one(&mut self, new_data: Value) -> String {
let name = Uuid::new_v4().to_string();
self.data.insert(name.clone(), new_data);
name
}

pub fn create_from_exist(instace_name: String, name: String) -> std::io::Result<Vec<String>> {
let filepath = format!("ADB_Data/json_engine/{}", name);
let mut files = Vec::new();
for entry in std::fs::read_dir(filepath)? {
let entry = entry?;
let path = entry.path();
if path.is_file() {
if let Some(file_name) = path.file_name() {
if let Some(file_name_str) = file_name.to_str() {
files.push(format!("ADB_Data/json_engine/{}/{}",instance_name,file_name_str.to_string());
}
}
}
}
Ok(files)
}

pub fn print_all(&self, key: Option<String>) {
match key {
Some(k) => {
if let Some(value) = self.data.get(&k) { // Проверяем наличие ключа в HashMap
println!("{:#?}", value);
} else {
println!("Ключ '{}' не найден", k);
}
},
None => println!("{:#?}", self.data),
}
}

pub fn commit(&self) -> Value {
let key = json!(self.data.clone());
// Запись данных в файл
let file_path = "data.json";
let json_string = serde_json::to_string_pretty(&self.data).unwrap();


let mut file = File::create(file_path).expect("Не удалось создать файл");
file.write_all(json_string.as_bytes()).expect("Не удалось записать в файл");

key
}
}

#[tokio::main]
async fn main() {
let mut je = JSONEngine::create_from_exist("instance_1".to_string());
println!("JE {:#?}",je );
}
Empty file.
5 changes: 5 additions & 0 deletions Plugins/MemoreDB/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Used by "mix format"
[
inputs: ["mix.exs", "config/*.exs"],
subdirectories: ["apps/*"]
]
10 changes: 10 additions & 0 deletions Plugins/MemoreDB/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/_build
/cover
/deps
/doc
/.fetch
erl_crash.dump
*.ez
*.beam
/config/*.secret.exs
.elixir_ls/
8 changes: 8 additions & 0 deletions Plugins/MemoreDB/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM elixir:latest

WORKDIR /workapp
COPY . .

CMD ["iex", "-S", "mix"]

EXPOSE 4040:4040
Loading

0 comments on commit 0a18131

Please sign in to comment.