Skip to content

Commit

Permalink
Merge pull request #25 from 0xBLCKLPTN/alice_database-dev
Browse files Browse the repository at this point in the history
Alice database dev
  • Loading branch information
0xBLCKLPTN authored Oct 24, 2024
2 parents e842ae8 + 7522fe5 commit 0e095c0
Show file tree
Hide file tree
Showing 13 changed files with 900 additions and 693 deletions.
24 changes: 24 additions & 0 deletions Plugins/Alice-Database/BUILD
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"
)

12 changes: 10 additions & 2 deletions Plugins/Alice-Database/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "Alice-Database_DBMS"
version = "1.0.0"
version = "1.2.0"
edition = "2021"
include = ["**/*.rs", "Cargo.toml"]
license = "MIT"
Expand All @@ -13,10 +13,18 @@ homepage = "https://github.com/0xBLCKLPTN/Kingdom-System"
chrono = "0.4.38"
env_logger = "0.11.5"
log = "0.4.22"
prost = "0.13.3"
serde = { version = "1.0.213", features = ["derive"] }
serde_json = "1.0.132"
simplelog = "0.12.2"
tokio = { version = "1.41.0", features = ["full"] }
tonic = "0.12.3"
uuid = { version = "1.11.0", features = ["v4"] }

[[test]]
name = "tests"
path = "src/tests.rs"
path = "src/main.rs"


[build-dependencies]
tonic-build = "0.12.3"
40 changes: 40 additions & 0 deletions Plugins/Alice-Database/WORKSPACE.bazel
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()

4 changes: 4 additions & 0 deletions Plugins/Alice-Database/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

fn main() {
tonic_build::compile_protos("proto/instance.proto").unwrap();
}
40 changes: 40 additions & 0 deletions Plugins/Alice-Database/proto/instance.proto
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);
}
6 changes: 6 additions & 0 deletions Plugins/Alice-Database/src/engines.rs
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),
}
71 changes: 71 additions & 0 deletions Plugins/Alice-Database/src/grpc.rs
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)
}
}

50 changes: 50 additions & 0 deletions Plugins/Alice-Database/src/instance.rs
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
}
}
Loading

0 comments on commit 0e095c0

Please sign in to comment.