-
-
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.
Merge pull request #25 from 0xBLCKLPTN/alice_database-dev
Alice database dev
- Loading branch information
Showing
13 changed files
with
900 additions
and
693 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
visibility = ["//visibility:public"] | ||
|
||
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_test", "rust_library") | ||
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps") | ||
|
||
|
||
rust_library( | ||
name = "alice_db_lib", | ||
|
||
# Specifies the source file for the binary. | ||
srcs = glob([ | ||
"src/*.rs", | ||
"src/**/*.rs", | ||
]), | ||
aliases = aliases(), | ||
#proc_macro_deps = all_crate_deps(), | ||
#deps = [ | ||
# all_crate_deps(normal=True) | ||
#], | ||
deps = all_crate_deps(normal = True), | ||
# Specifies the Rust edition to use for this binary. | ||
edition = "2021" | ||
) | ||
|
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,40 @@ | ||
# Загрузка необходимых внешних репозиториев | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
# <========== Настройка Rust для проекта =================== | ||
http_archive( | ||
name = "rules_rust", | ||
integrity = "sha256-Weev1uz2QztBlDA88JX6A1N72SucD1V8lBsaliM0TTg=", | ||
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.48.0/rules_rust-v0.48.0.tar.gz"], | ||
) | ||
|
||
# Загрузка зависимостей для Rust | ||
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains") | ||
rules_rust_dependencies() | ||
rust_register_toolchains() | ||
|
||
# Загрузка зависимостей для Rust Analyzer для улучшенной разработки | ||
load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies") | ||
rust_analyzer_dependencies() | ||
|
||
# Загрузка зависимостей для управления версиями crate | ||
load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") | ||
crate_universe_dependencies() | ||
|
||
# Определение репозитория для crate | ||
load("@rules_rust//crate_universe:defs.bzl", "crates_repository", "crate") | ||
crates_repository( | ||
name = "crate_index", | ||
cargo_lockfile = "//:Cargo.lock", # Путь к вашему Cargo.lock | ||
lockfile = "//:Cargo.Bazel.lock", # Путь к вашему замороженному файлу Bazel | ||
manifests = [ | ||
"//:Cargo.toml", # Путь к вашему Cargo.toml | ||
], | ||
# Должен соответствовать версии, представленной текущим зарегистрированным `rust_toolchain`. | ||
rust_version = "1.81.0", | ||
) | ||
|
||
# Загрузка всех crated из crate_index | ||
load("@crate_index//:defs.bzl", "crate_repositories") | ||
crate_repositories() | ||
|
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,4 @@ | ||
|
||
fn main() { | ||
tonic_build::compile_protos("proto/instance.proto").unwrap(); | ||
} |
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,40 @@ | ||
syntax = "proto3"; | ||
|
||
package instance; | ||
|
||
// Message definitions | ||
message Instance { | ||
string name = 1; | ||
string engine = 2; | ||
} | ||
|
||
message CreateInstanceRequest { | ||
string engine_type = 1; | ||
string root_path = 2; | ||
} | ||
|
||
message CreateInstanceResponse { | ||
string instance = 1; | ||
} | ||
|
||
message GetInstanceRequest { | ||
string instance_name = 1; | ||
} | ||
|
||
message GetInstanceResponse { | ||
string instance = 1; // Returning the instance | ||
} | ||
|
||
message GetAllInstancesRequest { | ||
string message = 1; | ||
} | ||
|
||
message GetAllInstancesResponse { | ||
repeated Instance instances = 1; | ||
} | ||
|
||
service InstanceService { | ||
rpc CreateInstance(CreateInstanceRequest) returns (CreateInstanceResponse); | ||
rpc GetInstance(GetInstanceRequest) returns (GetInstanceResponse); | ||
rpc GetAllInstances(GetAllInstancesRequest) returns (GetAllInstancesResponse); | ||
} |
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,6 @@ | ||
use crate::json_engine::JSONEngine; | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Engines { | ||
JSONEngine(JSONEngine), | ||
} |
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,71 @@ | ||
use tonic::{transport::Server, Request, Response, Status}; | ||
use uuid::Uuid; | ||
use std::path::PathBuf; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
// Import generated gRPC code | ||
pub mod instance { | ||
tonic::include_proto!("instance"); | ||
} | ||
|
||
use instance::{InstanceService, CreateInstanceRequest, CreateInstanceResponse, | ||
GetInstanceRequest, GetInstanceResponse, Instance}; | ||
|
||
// Engines enum represents the types of engines | ||
#[derive(Debug, Clone)] | ||
pub enum Engines { | ||
JSONEngine(JSONEngine), | ||
} | ||
|
||
// Your JSONEngine structure | ||
#[derive(Debug, Clone)] | ||
pub struct JSONEngine { | ||
// Add fields necessary for your JSON engine | ||
} | ||
|
||
impl JSONEngine { | ||
pub fn new(_root_path: &PathBuf) -> Self { | ||
// Initialize your JSONEngine as needed | ||
Self {} | ||
} | ||
} | ||
|
||
// Instance structure | ||
#[derive(Debug, Clone, Default)] | ||
pub struct Instance { | ||
pub name: String, | ||
pub engine: Engines, | ||
} | ||
|
||
// InstanceManager struct to manage instances | ||
#[derive(Debug, Default)] | ||
pub struct InstanceManager { | ||
pub name: String, | ||
pub instances: Vec<Instance>, | ||
} | ||
|
||
impl InstanceManager { | ||
pub fn new() -> Self { | ||
let name = Uuid::new_v4().to_string(); | ||
let instances: Vec<Instance> = vec![]; | ||
Self { name, instances } | ||
} | ||
|
||
pub fn create_instance(&mut self, engine_type: &str, root_path: &PathBuf) -> String { | ||
let instance_name: String = Uuid::new_v4().to_string(); | ||
|
||
let engine = match engine_type { | ||
"json_engine" => Engines::JSONEngine(JSONEngine::new(root_path)), | ||
_ => panic!("Engine not found"), | ||
}; | ||
|
||
let instance = Instance { engine, name: instance_name.clone() }; | ||
self.instances.push(instance); | ||
instance_name | ||
} | ||
|
||
pub fn get_instance(&self, instance_name: &str) -> Option<&Instance> { | ||
self.instances.iter().find(|i| i.name == instance_name) | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -1,2 +1,52 @@ | ||
use crate::Engines; | ||
use uuid::Uuid; | ||
use std::path::PathBuf; | ||
use crate::JSONEngine; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Instance { | ||
pub name: String, | ||
pub engine: Engines, | ||
} | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct InstanceManager { | ||
pub name: String, | ||
pub instances: Vec<Instance> | ||
} | ||
|
||
|
||
impl InstanceManager { | ||
pub fn new() -> Self { | ||
let name = Uuid::new_v4().to_string(); | ||
let mut instances: Vec<Instance> = vec![]; | ||
Self {name, instances} | ||
} | ||
|
||
pub fn create_instance(&mut self, engine_type: &str, root_path: &PathBuf) -> String { | ||
let instance_name: String = Uuid::new_v4().to_string(); | ||
|
||
let mut engine = match engine_type { | ||
"json_engine" => Engines::JSONEngine(JSONEngine::new(&root_path)), | ||
_ => panic!("Engine not found"), | ||
}; | ||
let mut instance = Instance {engine, name: instance_name.clone()}; | ||
self.instances.push(instance); | ||
instance_name | ||
} | ||
pub fn get_instance(&self, instance_name: &str) -> Option<&Instance> { | ||
self.instances.iter().find(|i| i.name == instance_name) | ||
} | ||
// Method to mutate the engine of an existing instance | ||
|
||
pub fn get_mutable_engine(&mut self, instance_name: &str) -> Option<&mut JSONEngine> { | ||
for instance in &mut self.instances { | ||
if instance.name == instance_name { | ||
if let Engines::JSONEngine(ref mut engine) = instance.engine { | ||
return Some(engine); | ||
} | ||
} | ||
} | ||
None | ||
} | ||
} |
Oops, something went wrong.