-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea17f22
commit 0a18131
Showing
32 changed files
with
1,458 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Plugins/Alice-Database_v2/src/ADB_Data/json_engine/instance_1/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
Plugins/Alice-Database_v2/src/ADB_Data/json_engine/instance_1/users.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/*"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.