Skip to content

Commit 22b7896

Browse files
committed
Add kyu-api README and crate metadata
1 parent 43c1f71 commit 22b7896

2 files changed

Lines changed: 151 additions & 0 deletions

File tree

crates/kyu-api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
edition = "2024"
55
description = "Database and Connection API for KyuGraph with Arrow Flight support"
66
license = "MIT"
7+
readme = "README.md"
78
repository = "https://github.com/offbit-ai/kyugraph"
89

910
[dependencies]

crates/kyu-api/README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# kyu-api
2+
3+
Database and Connection API for [KyuGraph](https://crates.io/crates/kyu-graph) with Arrow Flight support.
4+
5+
This crate is the internal engine API. Most users should depend on [`kyu-graph`](https://crates.io/crates/kyu-graph) instead, which re-exports the public surface from this crate.
6+
7+
## Core Types
8+
9+
| Type | Description |
10+
|------|-------------|
11+
| `Database` | Top-level entry point owning catalog, storage, WAL, and transaction manager |
12+
| `Connection` | Executes Cypher queries and DDL against a database |
13+
| `NodeGroupStorage` | Columnar storage backed by NodeGroup/ColumnChunk |
14+
15+
## Usage
16+
17+
```rust
18+
use kyu_api::{Database, Connection};
19+
20+
// In-memory
21+
let db = Database::in_memory();
22+
let conn = db.connect();
23+
conn.query("CREATE NODE TABLE Person (id INT64, name STRING, PRIMARY KEY (id))").unwrap();
24+
conn.query("CREATE (p:Person {id: 1, name: 'Alice'})").unwrap();
25+
26+
let result = conn.query("MATCH (p:Person) RETURN p.name").unwrap();
27+
for row in result.iter_rows() {
28+
println!("{:?}", row);
29+
}
30+
```
31+
32+
### Persistent Database
33+
34+
```rust
35+
use kyu_api::Database;
36+
37+
let db = Database::open(std::path::Path::new("./my_graph")).unwrap();
38+
let conn = db.connect();
39+
// Schema + data persisted to disk via WAL + checkpointing.
40+
```
41+
42+
### Parameterized Queries
43+
44+
```rust
45+
use std::collections::HashMap;
46+
use kyu_types::TypedValue;
47+
48+
let mut params = HashMap::new();
49+
params.insert("min_age".to_string(), TypedValue::Int64(25));
50+
let result = conn.query_with_params(
51+
"MATCH (p:Person) WHERE p.age > $min_age RETURN p.name",
52+
params,
53+
).unwrap();
54+
```
55+
56+
### Full VM Execution (params + env)
57+
58+
```rust
59+
use std::collections::HashMap;
60+
use kyu_types::TypedValue;
61+
62+
let params = HashMap::new();
63+
let env = HashMap::new();
64+
let result = conn.execute("MATCH (n) RETURN n", params, env).unwrap();
65+
```
66+
67+
### Delta Fast Path
68+
69+
Conflict-free idempotent upserts bypassing OCC for high-throughput ingestion:
70+
71+
```rust
72+
use kyu_delta::{DeltaBatchBuilder, DeltaValue};
73+
74+
let batch = DeltaBatchBuilder::new("source:my-pipeline", 1000)
75+
.upsert_node("Person", "1", vec![], [("name", DeltaValue::String("Alice".into()))])
76+
.build();
77+
let stats = conn.apply_delta(batch).unwrap();
78+
```
79+
80+
### Extensions
81+
82+
```rust
83+
use kyu_api::Database;
84+
use kyu_extension::Extension;
85+
86+
let mut db = Database::in_memory();
87+
// db.register_extension(Box::new(my_ext));
88+
let conn = db.connect();
89+
```
90+
91+
### Arrow Flight Server
92+
93+
Expose KyuGraph as an Arrow Flight gRPC endpoint:
94+
95+
```rust
96+
use std::sync::Arc;
97+
use kyu_api::{Database, serve_flight};
98+
99+
let db = Arc::new(Database::in_memory());
100+
// serve_flight(db, "0.0.0.0", 50051).await.unwrap();
101+
```
102+
103+
Convert query results to Arrow RecordBatch:
104+
105+
```rust
106+
use kyu_api::to_record_batch;
107+
108+
let result = conn.query("MATCH (p:Person) RETURN p.name, p.age").unwrap();
109+
if let Some(batch) = to_record_batch(&result) {
110+
println!("Arrow schema: {:?}", batch.schema());
111+
}
112+
```
113+
114+
## Architecture
115+
116+
```
117+
Application
118+
119+
120+
┌─────────┐ ┌────────────┐
121+
│ Database │────▶│ Connection │ ← you are here (kyu-api)
122+
└─────────┘ └────────────┘
123+
│ │
124+
▼ ▼
125+
┌────────┐ ┌──────────────┐
126+
│Catalog │ │ kyu-executor │
127+
└────────┘ └──────────────┘
128+
│ │
129+
▼ ▼
130+
┌──────────────────────────┐
131+
│ kyu-storage (columnar) │
132+
└──────────────────────────┘
133+
134+
135+
┌──────────────────────────┐
136+
│ kyu-transaction (WAL) │
137+
└──────────────────────────┘
138+
```
139+
140+
## Query Pipeline
141+
142+
1. **Parse**`kyu-parser` lexes and parses Cypher into an AST
143+
2. **Bind**`kyu-binder` resolves names against the catalog
144+
3. **Plan**`kyu-planner` builds and optimizes a logical plan
145+
4. **Execute**`kyu-executor` runs the plan against storage
146+
5. **Commit**`kyu-transaction` persists via WAL + checkpoint
147+
148+
## License
149+
150+
MIT

0 commit comments

Comments
 (0)