Skip to main content

kyu_graph/
lib.rs

1//! KyuGraph — high-performance embedded property graph database.
2//!
3//! KyuGraph is a pure-Rust embedded graph database implementing the openCypher
4//! query language. It uses columnar storage, vectorized execution, and optional
5//! Cranelift JIT compilation for analytical graph workloads.
6//!
7//! # Quick Start
8//!
9//! ```no_run
10//! use kyu_graph::{Database, TypedValue};
11//!
12//! // In-memory database
13//! let db = Database::in_memory();
14//! let conn = db.connect();
15//!
16//! // Create schema
17//! conn.query("CREATE NODE TABLE Person (id INT64, name STRING, age INT64, PRIMARY KEY (id))")
18//!     .unwrap();
19//! conn.query("CREATE REL TABLE KNOWS (FROM Person TO Person)")
20//!     .unwrap();
21//!
22//! // Insert data
23//! conn.query("CREATE (p:Person {id: 1, name: 'Alice', age: 30})").unwrap();
24//! conn.query("CREATE (p:Person {id: 2, name: 'Bob', age: 25})").unwrap();
25//!
26//! // Query
27//! let result = conn.query("MATCH (p:Person) WHERE p.age > 20 RETURN p.name, p.age").unwrap();
28//! for row in result.iter_rows() {
29//!     println!("{:?}", row);
30//! }
31//! ```
32//!
33//! # Persistent Database
34//!
35//! ```no_run
36//! use kyu_graph::Database;
37//!
38//! let db = Database::open(std::path::Path::new("./my_graph")).unwrap();
39//! let conn = db.connect();
40//! conn.query("CREATE NODE TABLE Log (id INT64, msg STRING, PRIMARY KEY (id))").unwrap();
41//! // Data is checkpointed to disk automatically.
42//! ```
43//!
44//! # Bulk Data Import
45//!
46//! ```no_run
47//! use kyu_graph::Database;
48//!
49//! let db = Database::in_memory();
50//! let conn = db.connect();
51//! conn.query("CREATE NODE TABLE Person (id INT64, name STRING, PRIMARY KEY (id))").unwrap();
52//! conn.query("COPY Person FROM 'people.csv'").unwrap();
53//! ```
54//!
55//! # Parameterized Queries
56//!
57//! Pass dynamic values safely via `$param` placeholders instead of string
58//! interpolation. Use the re-exported `json!` macro and `BindContext` for
59//! ergonomic construction from JSON:
60//!
61//! ```no_run
62//! use kyu_graph::{Database, BindContext, json};
63//!
64//! let db = Database::in_memory();
65//! let conn = db.connect();
66//! conn.query("CREATE NODE TABLE Person (id INT64, name STRING, age INT64, PRIMARY KEY (id))")
67//!     .unwrap();
68//! conn.query("CREATE (p:Person {id: 1, name: 'Alice', age: 30})").unwrap();
69//!
70//! // From json! macro
71//! let ctx = BindContext::with_params_json(json!({"min_age": 25}));
72//!
73//! // From a JSON string (e.g. read from a config file or HTTP request body)
74//! let ctx = BindContext::with_params_str(r#"{"min_age": 25}"#).unwrap();
75//!
76//! // Or use HashMap<String, TypedValue> directly
77//! use std::collections::HashMap;
78//! use kyu_graph::TypedValue;
79//! let mut params = HashMap::new();
80//! params.insert("min_age".to_string(), TypedValue::Int64(25));
81//! let result = conn.query_with_params(
82//!     "MATCH (p:Person) WHERE p.age > $min_age RETURN p.name",
83//!     params,
84//! ).unwrap();
85//! ```
86//!
87//! For full VM-style execution with both parameters and environment bindings,
88//! use [`Connection::execute`].
89//!
90//! # Extensions
91//!
92//! KyuGraph supports pluggable extensions for graph algorithms, full-text search,
93//! vector similarity, and more. Extensions are registered on the database instance
94//! before creating connections.
95//!
96//! ```no_run
97//! use kyu_graph::{Database, Extension};
98//!
99//! let mut db = Database::in_memory();
100//! // db.register_extension(Box::new(my_extension));
101//! let conn = db.connect();
102//! // conn.query("CALL ext.procedure(args)").unwrap();
103//! ```
104
105// ---- Core API ----
106
107pub use kyu_api::{Connection, Database};
108
109// ---- Bind-Time Context ----
110
111pub use kyu_binder::BindContext;
112
113// ---- JSON ----
114
115/// Re-export `serde_json::json!` for ergonomic construction of params and env.
116pub use serde_json::json;
117
118// ---- Query Results ----
119
120pub use kyu_executor::QueryResult;
121
122// ---- Storage ----
123
124pub use kyu_api::NodeGroupStorage;
125
126// ---- Data Import ----
127
128pub use kyu_copy::{
129    ArrowIpcReader, CsvReader, DataReader, KafkaReader, ParquetReader, open_reader,
130};
131
132// ---- Delta Fast Path ----
133
134pub use kyu_delta::{
135    DeltaBatch, DeltaBatchBuilder, DeltaStats, DeltaValue, GraphDelta, NodeKey, VectorClock,
136};
137
138// ---- Type System ----
139
140pub use kyu_types::{LogicalType, TypedValue};
141
142// ---- Error Handling ----
143
144pub use kyu_common::{KyuError, KyuResult};
145
146// ---- Configuration ----
147
148pub use kyu_common::DatabaseConfig;
149
150// ---- Extensions ----
151
152pub use kyu_extension::{Extension, ProcColumn, ProcParam, ProcRow, ProcedureSignature};
153
154// ---- Arrow Flight ----
155
156pub use kyu_api::{serve_flight, to_record_batch};
157
158/// Re-exports of types used less frequently but needed for advanced usage.
159pub mod types {
160    pub use kyu_types::{Interval, LogicalType, PhysicalType, TypedValue};
161}