CGDB is a Contextual Graph Database designed to handle complex data relationships with dynamic schema evolution and context-aware querying. This database system is written in Rust and aims to provide an efficient, scalable, and flexible solution for managing interconnected data.
- Contextual Nodes and Edges
- Dynamic Schema Evolution
- Multi-Dimensional Relationships
- Contextual Queries
- Temporal and Spatial Awareness
- Adaptive Indexing
- Intelligent Data Sharding
- Semantic Understanding
To install CGDB, you need to have Rust and Cargo installed on your machine. Follow these steps to set up the project:
-
Clone the Repository
git clone https://github.com/yourusername/cgdb.git cd cgdb
-
Build the Project
cargo build
-
Run the Project
cargo run
To compile the project, simply use Cargo:
cargo build --release
This will compile the project in release mode, optimizing for performance.
Create an instance of the ContextService
to manage contexts, nodes, and edges:
use services::context_service::ContextService;
let mut context_service = ContextService::new();
Add contexts, nodes, and edges to the database:
use models::context::Context;
use database::node::Node;
use database::edge::Edge;
// Create a new context
let context = Context::new(1, "Sample Context");
context_service.add_context(context);
// Add nodes to the context
context_service.add_node_to_context(1, 101, "Node 1");
context_service.add_node_to_context(1, 102, "Node 2");
// Add an edge between nodes
context_service.add_edge_to_context(1, 101, 102, "Edge from Node 1 to Node 2");
Retrieve and query data from the database:
// Retrieve and display the context
if let Some(retrieved_context) = context_service.get_context(1) {
println!("Context: {:?}", retrieved_context);
}
// Retrieve and display a node
if let Some(node) = context_service.schema.get_node(101) {
println!("Node: {:?}", node);
}
// Retrieve and display an edge
if let Some(edge) = context_service.schema.get_edge(101, 102) {
println!("Edge: {:?}", edge);
}
// Query nodes by property
if let Some(node) = context_service.schema.nodes.get_mut(&101) {
node.add_property("key", "value");
}
let nodes_with_property = context_service.schema.query_nodes_by_property("key", "value");
for node in nodes_with_property {
println!("Node with property: {:?}", node);
}
Here's an example of a full program using CGDB:
mod database;
mod models;
mod services;
mod api;
mod config;
mod utils;
use models::context::Context;
use database::node::Node;
use database::edge::Edge;
use services::context_service::ContextService;
fn main() {
// Initialize the context service
let mut context_service = ContextService::new();
// Create a new context
let context = Context::new(1, "Sample Context");
context_service.add_context(context);
// Add nodes to the context
context_service.add_node_to_context(1, 101, "Node 1");
context_service.add_node_to_context(1, 102, "Node 2");
// Add an edge between nodes
context_service.add_edge_to_context(1, 101, 102, "Edge from Node 1 to Node 2");
// Retrieve and display the context
if let Some(retrieved_context) = context_service.get_context(1) {
println!("Context: {:?}", retrieved_context);
}
// Retrieve and display a node
if let Some(node) = context_service.schema.get_node(101) {
println!("Node: {:?}", node);
}
// Retrieve and display an edge
if let Some(edge) = context_service.schema.get_edge(101, 102) {
println!("Edge: {:?}", edge);
}
// Query nodes by property (for demonstration, properties need to be added to nodes)
// Example of adding a property to a node
if let Some(node) = context_service.schema.nodes.get_mut(&101) {
node.add_property("key", "value");
}
let nodes_with_property = context_service.schema.query_nodes_by_property("key", "value");
for node in nodes_with_property {
println!("Node with property: {:?}", node);
}
}
-
Compile the Project:
cargo build --release
-
Run the Application in the Background:
nohup ./target/release/cgdb &
For a more robust solution, create a systemd
service file to manage your daemon.
-
Create the Service File:
sudo nano /etc/systemd/system/cgdb.service
-
Add the Following Content:
[Unit] Description=CGDB Service After=network.target [Service] ExecStart=/path/to/your/cgdb/target/release/cgdb Restart=on-failure User=youruser Group=yourgroup [Install] WantedBy=multi-user.target
-
Enable and Start the Service:
sudo systemctl enable cgdb sudo systemctl start cgdb
You can connect to your running daemon using any HTTP client. Here are some examples using curl
:
-
Add a Context:
curl http://localhost:3000/add_context
-
Get a Context:
curl http://localhost:3000/get_context