A high-performance, embedded message-based RDBMS written in Go, powered by BadgerDB with a complete TCP server, query language (DSL), and protocol system for entity mapping.
- 3-Layer Architecture: Clean separation between Engine, Store Manager, and Database layers
- Hybrid Storage: RAM buffering with asynchronous disk persistence (500ms flush)
- Full Indexing: Automatic reverse indexing for every column
- Laravel-style Validation & Formatting: Schema-level rules (e.g.,
required|min:18,trim|upper) - Production Ready: Structured logging, graceful shutdown, configuration via environment
- TCP Server: Multi-client support with connection pooling
- Message Router: Routes requests to database, DSL, or extensions
- Protocol System: Maps entity aliases to actual DB/table names with relationships
- DSL Query Engine: SQL-like query language with filters, projections, and aggregations
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TCP Server (Port 8080) β
β Message Protocol (\x04) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Message Router β
β Routes: database | onql | protocol | schema β
βββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββββ¬ββββββββββββββββ
β β β β
βΌ βΌ βΌ βΌ
ββββββββββββ ββββββββ ββββββββββββ ββββββββββββ
β Database β β DSL β β Protocol β β Schema β
β Handler β βEngineβ βExtension β βExtension β
ββββββ¬ββββββ ββββ¬ββββ ββββββ¬ββββββ ββββββ¬ββββββ
β β β β
ββββββββββββ΄βββββββββββ΄βββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Database Layer β
β (Validation/Format) β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Store Manager β
β (Buffer/Flush/Index) β
ββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β BadgerDB Engine β
β (LSM Tree Store) β
ββββββββββββββββββββββββ
The Protocol System allows you to define entity aliases that map to actual database tables with field mappings and relationships.
{
"database": "mydb",
"entities": {
"users": {
"table": "accounts",
"fields": {
"id": "account_id",
"name": "full_name",
"email": "email_address"
},
"relations": {
"orders": {
"type": "otm",
"entity": "orders",
"fk_field": "id:user_id"
}
},
"context": {
"user": "mydb.users[id=$1]",
"admin": "mydb.users[role='admin']"
}
}
}
}oto(One-to-One): Single related recordotm(One-to-Many): Multiple related recordsmto(Many-to-One): Reverse of one-to-manymtm(Many-to-Many): Through junction table
Store a Protocol:
{
"target": "protocol",
"payload": ["set", "mypassword", {...protocol_data...}]
}Retrieve Protocol:
{
"target": "protocol",
"payload": ["desc", "mypassword"]
}Delete Protocol:
{
"target": "protocol",
"payload": ["drop", "mypassword"]
}The DSL (Domain Specific Language) allows SQL-like queries with entity aliases:
mydb.users[age>18].name
mydb.orders[status='pending'].customer.name
mydb.products._count()
Features:
- Entity-based queries (uses protocol mappings)
- Filtering with conditions
- Relationship traversal
- Aggregations (count, sum, avg, etc.)
- Projections and field selection
All communication uses JSON messages with this structure:
{
"id": "sender_id",
"target": "database|onql|protocol|schema",
"rid": "request_id",
"type": "request|response",
"payload": "json_string"
}Messages are delimited by \x04 (EOT character).
{
"target": "database",
"payload": {
"function": "GetDatabases|CreateDatabase|GetTables|...",
"args": [...]
}
}{
"target": "onql",
"payload": {
"protopass": "mypassword",
"query": "mydb.users[age>18]",
"ctxkey": "user",
"ctxvalues": ["123"]
}
}- Go 1.21+
git clone <repo-url>
cd rdbms
go mod tidygo run examples/server_demo.goThe server starts on port 8080 by default.
Environment variables:
DB_PATH: Data storage path (default:./store)FLUSH_INTERVAL: Buffer flush interval (default:500ms)LOG_LEVEL:DEBUG|INFO|WARN|ERROR(default:INFO)
rdbms/
βββ engine/ # BadgerDB wrapper
βββ storemanager/ # Buffer, indexing, schema
βββ database/ # Validation, formatting, protocols
βββ dsl/ # Query language parser & evaluator
βββ router/ # Message routing
βββ server/ # TCP server
βββ extensions/ # Extension system
β βββ protocol/ # Protocol management extension
β βββ schema/ # Schema management extension
βββ config/ # Configuration loader
βββ logger/ # Structured logging
βββ examples/ # Demo applications
- Multi-tenant Applications: Use protocols for tenant isolation
- API Backends: Expose via TCP with custom client libraries
- Embedded Systems: Lightweight, single-binary database
- Real-time Applications: Fast RAM access with disk durability
- Microservices: Message-based communication between services
See examples/ directory for:
protocol_demo.go- Protocol system demonstrationserver_demo.go- TCP server with clientdsl_demo.go- DSL query examples
- Context Queries: Parameterized queries with
$1, $2placeholders - Field Mapping: Alias fields to actual column names
- Relationship Traversal: Navigate through entity relationships
- Extension System: Add custom handlers via extensions
- Graceful Shutdown: Ensures data integrity on exit
Built with β€οΈ using Go and BadgerDB