Hanzo DB - Multi-Backend Database Abstraction
A unified database abstraction layer for Hanzo Node that supports multiple backend databases, each optimized for different workloads.
Supported Backends
| Backend | Best For | Features |
|---|---|---|
| LanceDB | Vector Search, AI/ML | • Native vector operations• Multimodal storage• Columnar format• Fast similarity search |
| DuckDB | Analytics, OLAP | • In-process analytical database• SQL support• Columnar storage• Fast aggregations |
| PostgreSQL | Transactional, OLTP | • ACID compliance• Rich SQL features• Extensions (pgvector)• Battle-tested |
| Redis | Caching, Real-time | • In-memory storage• Pub/sub support• TTL/expiration• Extremely fast |
| SQLite | Embedded, Lightweight | • Zero-configuration• Single file• Serverless• Wide compatibility |
Usage
use ;
// Automatically select backend based on workload
let config = HanzoDbConfig ;
// Or explicitly choose a backend
let config = HanzoDbConfig ;
let db = connect.await?;
// Use unified interface regardless of backend
db.create_table.await?;
db.insert.await?;
let results = db.vector_search.await?;
Features
- Unified Interface: Same API across all backends
- Automatic Backend Selection: Choose optimal backend based on workload
- Migration Support: Move data between backends
- Connection Pooling: Efficient resource management
- Transaction Support: ACID guarantees where supported
- Vector Operations: Native support in LanceDB, extension support in PostgreSQL
Configuration
Environment Variables
# Select default backend
HANZO_DB_BACKEND=lancedb # lancedb, duckdb, postgresql, redis, sqlite
# Backend-specific configuration
HANZO_DB_PATH=./storage/hanzo-db
HANZO_DB_URL=postgresql://user:pass@localhost/hanzo
HANZO_REDIS_URL=redis://localhost:6379
Feature Flags
[]
= { = "1.0", = ["lancedb", "duckdb", "postgres"] }
Migration
Migrate from one backend to another:
# From SQLite to LanceDB
# From LanceDB to PostgreSQL
Performance Characteristics
| Operation | LanceDB | DuckDB | PostgreSQL | Redis | SQLite |
|---|---|---|---|---|---|
| Vector Search | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐ | ⭐ | ⭐ |
| Analytics | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐ | ⭐⭐ |
| Transactions | ⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐⭐ |
| Caching | ⭐⭐ | ⭐ | ⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ |
| Embedded | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐ | ⭐ | ⭐⭐⭐⭐⭐ |
License
Apache 2.0