this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 80 lines 2.8 kB view raw
1use gigabrain::Graph; 2use gigabrain::cypher::parse_cypher; 3use gigabrain::storage::MemoryStore; 4use gigabrain::server::{ApiServer, ServerConfig}; 5use tracing::{info, warn}; 6use tracing_subscriber; 7 8#[tokio::main] 9async fn main() -> Result<(), Box<dyn std::error::Error>> { 10 tracing_subscriber::fmt() 11 .with_max_level(tracing::Level::INFO) 12 .init(); 13 14 info!("Starting GigaBrain Graph Database"); 15 16 let graph = std::sync::Arc::new(Graph::new()); 17 18 { 19 let mut schema = graph.schema().write(); 20 let _person_label = schema.get_or_create_label("Person"); 21 let _name_prop = schema.get_or_create_property_key("name"); 22 let _age_prop = schema.get_or_create_property_key("age"); 23 let knows_rel = schema.get_or_create_relationship_type("KNOWS"); 24 drop(schema); 25 26 let alice = graph.create_node(); 27 let bob = graph.create_node(); 28 let charlie = graph.create_node(); 29 30 graph.create_relationship(alice, bob, knows_rel)?; 31 graph.create_relationship(bob, charlie, knows_rel)?; 32 } 33 34 info!("Created sample graph with 3 nodes and 2 relationships"); 35 36 let query = "MATCH (n:Person)-[:KNOWS]->(m) RETURN n, m"; 37 match parse_cypher(query) { 38 Ok(parsed) => { 39 info!("Successfully parsed Cypher query: {:?}", parsed); 40 41 // Execute the query 42 let executor = gigabrain::cypher::QueryExecutor::new(graph.clone()); 43 match executor.execute_query(&parsed).await { 44 Ok(result) => { 45 info!("Query executed successfully!"); 46 info!("Columns: {:?}", result.columns); 47 info!("Rows: {} returned", result.rows.len()); 48 for (i, row) in result.rows.iter().enumerate() { 49 info!("Row {}: {:?}", i, row.values); 50 } 51 } 52 Err(e) => { 53 warn!("Failed to execute query: {}", e); 54 } 55 } 56 } 57 Err(e) => { 58 warn!("Failed to parse Cypher query: {}", e); 59 } 60 } 61 62 let _storage = MemoryStore::new(); 63 info!("Initialized persistent storage"); 64 65 info!("GigaBrain Graph Database started successfully!"); 66 67 // Start the API server 68 let config = ServerConfig::default(); 69 let server = ApiServer::new(graph, config); 70 71 info!("Starting API servers..."); 72 info!("REST API will be available at: http://localhost:3000"); 73 info!("gRPC API will be available at: http://localhost:50051"); 74 info!("API documentation: http://localhost:3000/api/v1/docs"); 75 76 // This will run indefinitely serving requests 77 server.start().await?; 78 79 Ok(()) 80}