GraphLite SDK
High-level, ergonomic Rust SDK for GraphLite - the fast, embedded graph database.
Overview
The GraphLite SDK provides a developer-friendly API for working with GraphLite databases in Rust applications. It follows patterns from popular embedded databases like SQLite (rusqlite) while providing graph-specific features.
Features
- ✅ Simple API - Clean, intuitive interface following SQLite/rusqlite conventions
- ✅ Session Management - User context and permissions support
- ✅ Transactions - ACID guarantees with automatic rollback (RAII pattern)
- ✅ Query Builder - Fluent API for constructing GQL queries
- ✅ Typed Results - Deserialize query results into Rust structs
- ✅ Zero External Dependencies - Fully embedded, no server required
- ⏳ Connection Pooling - Efficient concurrent access (future)
- ⏳ Async Support - Full tokio integration (future)
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
Basic usage:
use ;
Core Concepts
Opening a Database
GraphLite is an embedded database - no server required. Just open a directory:
let db = open?;
This creates or opens a database at the specified path.
Sessions
Unlike SQLite, GraphLite uses sessions for user context and permissions:
let session = db.session?;
Sessions provide:
- User authentication and authorization
- Transaction isolation
- Audit logging
Executing Queries
Simple query execution:
let result = session.query?;
Or for statements that don't return results:
session.execute?;
Transactions
Transactions follow the rusqlite pattern with automatic rollback:
// Transaction with explicit commit
let mut tx = session.transaction?;
tx.execute?;
tx.execute?;
tx.commit?; // Persist changes
// Transaction with automatic rollback
Query Builder
Build queries fluently:
let result = session.query_builder
.match_pattern
.where_clause
.return_clause
.order_by
.limit
.execute?;
Typed Results
Deserialize results into Rust structs:
use Deserialize;
let result = session.query?;
let typed = from;
let people: = typed.deserialize_rows?;
Examples
Basic CRUD Operations
use GraphLite;
Transaction Example
use GraphLite;
Query Builder Example
use GraphLite;
Typed Deserialization Example
use ;
use Deserialize;
API Comparison with SQLite
GraphLite SDK follows similar patterns to rusqlite but adapted for graph databases:
| Operation | rusqlite (SQLite) | graphlite-sdk (GraphLite) |
|---|---|---|
| Open DB | Connection::open() |
GraphLite::open() |
| Execute | conn.execute() |
session.execute() |
| Query | conn.query_row() |
session.query() |
| Transaction | conn.transaction()? |
session.transaction()? |
| Commit | tx.commit()? |
tx.commit()? |
| Rollback | tx.rollback()? or drop |
tx.rollback()? or drop |
Key Differences:
- GraphLite uses sessions for user context (SQLite doesn't have sessions)
- GraphLite uses GQL (Graph Query Language) instead of SQL
- GraphLite is optimized for graph data (nodes, edges, paths)
Architecture
Your Application
│
▼
┌─────────────────────────┐
│ GraphLite SDK │
│ - GraphLite │ ← You are here
│ - Session │
│ - Transaction │
│ - QueryBuilder │
│ - TypedResult │
└─────────────────────────┘
│
▼
┌─────────────────────────┐
│ GraphLite Core │
│ - QueryCoordinator │
│ - Storage Engine │
│ - Catalog Manager │
└─────────────────────────┘
Language Bindings
The GraphLite SDK is specifically for Rust applications. For other languages:
- Python - Use
bindings/python/(via FFI) - Java - Use
bindings/java/(via JNI) - JavaScript/Node.js - Use
bindings/javascript/(via FFI/WASM) - Kotlin - Use
bindings/kotlin/(via JNI)
See the main MULTI_LANGUAGE_BINDINGS_DESIGN.md for details.
Performance
GraphLite SDK provides zero-overhead abstractions:
- Direct Rust function calls (no FFI overhead)
- No serialization for query results (unlike language bindings)
- Compile-time optimizations
- Same performance as using the core library directly
Benchmark comparison:
- Rust SDK: ~100% of native performance
- Python bindings (via FFI): ~80-90% of native
- JavaScript bindings (via WASM): ~70-80% of native
Documentation
Examples
Run the examples:
# Basic usage example
# More examples coming soon
Contributing
Contributions welcome! Areas where help is needed:
- ORM Features - Derive macros for mapping structs to graph nodes
- Query Macros - Compile-time query validation
- Async Support - Full tokio integration
- Connection Pooling - Multi-threaded access patterns
- Graph Algorithms - Built-in graph algorithms (shortest path, centrality, etc.)
License
Apache-2.0 - See LICENSE for details.