dog-typedb
TypeDB database integration for DogRS - adapters, utilities, and TypeQL query builders
dog-typedb provides seamless TypeDB integration for the DogRS ecosystem with robust query handling, automatic transaction management, TypeDB inference and rules support, and TypeDB Studio-compatible response formatting.
Features
- Complete TypeQL support - Match, fetch, insert, delete, and schema operations
- TypeDB inference and rules - Full support for TypeDB's reasoning capabilities
- Automatic transaction management - Smart routing for read/write/schema operations
- TypeDB Studio compatibility - Response format matches TypeDB Studio exactly
- Production-ready - Comprehensive error handling and robust query processing
Quick Start
Basic Usage
use execute_typedb_query;
use ;
use Arc;
// Setup TypeDB connection
let credentials = new;
let options = new?;
let driver = new;
// Create database if it doesn't exist (optional)
if !driver.databases.all.await?.iter.any
// Load schema and functions (optional - only if you have .tql files)
use load_schema_from_file;
load_schema_from_file.await?;
// Execute queries directly
let result = execute_typedb_query.await?;
println!;
Using TypeDBAdapter Directly
use TypeDBAdapter;
use json;
// Create adapter with your TypeDB state
let adapter = new;
// Read queries
let result = adapter.read.await?;
// Write queries
let result = adapter.write.await?;
// Schema queries
let result = adapter.schema.await?;
Integration with DogRS Services
For production applications, integrate with the DogRS service layer:
use ;
use ;
use DogAxum;
use Value;
use Arc;
// 1. Setup TypeDB state in your application
// 2. Initialize in your app
let ax = new.await?;
setup_db.await?;
let state = ax.app.?;
// 3. Create service with TypeDB adapter
Direct Query Execution
For lower-level usage, you can call execute_typedb_query directly:
// Match queries → conceptRows
let result = execute_typedb_query.await?;
// Fetch queries → conceptDocuments
let result = execute_typedb_query.await?;
// Aggregation queries → conceptRows
let result = execute_typedb_query.await?;
TypeDB Studio Compatibility
All responses use the exact same format as TypeDB Studio:
Error Handling
dog-typedb provides comprehensive error handling for all TypeDB operations:
match execute_typedb_query.await
Schema Loading
Load TypeDB schemas from files:
use load_schema_from_file;
let result = load_schema_from_file.await?;
Architecture
dog-typedb integrates seamlessly with the DogRS ecosystem:
┌─────────────────┐
│ Your App │ ← Business logic
└─────────────────┘
│
┌────┴────┐
│ │
┌───▼───┐ ┌──▼──────┐
│dog- │ │dog- │ ← Adapters
│axum │ │typedb │
└───────┘ └─────────┘
│ │
└────┬────┘
▼
┌─────────────────┐
│ dog-core │ ← Core abstractions
└─────────────────┘
│
▼
┌─────────────────┐
│ TypeDB │ ← Database
└─────────────────┘
Examples
Complete examples available in dog-examples/:
- social-typedb - Social network with TypeDB
- fleet-queue - Fleet management with TypeDB functions
TypeDB Version Support
- TypeDB 3.0+ - Full support including parameterized functions
- TypeDB 2.x - Core functionality supported
License
MIT OR Apache-2.0
Made by Jitpomi