l8orm

ORM

Object-relational mapping as a service.

Overview

L8ORM is a distributed, horizontally and vertically scalable ORM service. It automatically converts between Go objects and PostgreSQL, with built-in time-series support via TimescaleDB, query caching, write-through caching, and service mesh integration.

Two-Layer Conversion

Objects convert through an intermediate relational format: Go objects to L8OrmRData (protobuf-based relational format) to database rows. This decouples object structure from storage layout.

Core Interfaces

IORM
Read, Write, Delete, Close. Pluggable database implementations.
ITSDB
AddTSDB, GetTSDB, Close. Time-series database interface.
IORMRelational
Raw relational access via ReadRelational and WriteRelational.

PostgreSQL Plugin

Native PostgreSQL integration with connection pooling, upserts (INSERT ON CONFLICT), automatic table and index creation, prepared statement caching, and wildcard query support (* converted to SQL LIKE with %).

Time-Series Database

TimescaleDB-backed time-series storage. Hypertable chunking. Separate from the relational ORM. Write time-series data points and query by property ID within a time range.

Caching

Query Cache
30-second TTL for pagination optimization with background cleanup
Write-Through Cache
Optional in-memory layer with automatic invalidation on writes/deletes. Initialized from existing database contents on startup.

Composite Keys

ParentKey + RecKey scheme supporting nested structures, slices, and maps. ParentKey encodes the object hierarchy path. RecKey identifies the specific field, slice index, or map key.

Service Mesh Integration

Activate an ORM service on the Layer 8 service mesh with cache, TSDB routing, and Before/After callbacks in a single call.

Data Model

L8OrmRData
Root container mapping table names to schemas
L8OrmTable
Column definitions and instance rows
L8OrmInstanceRows
Rows grouped by parent key
L8OrmRow
Single record with composite key and column values

SQL Generation

Statement builders for SELECT, INSERT (upsert), UPDATE with COALESCE (PATCH semantics), DELETE, and metadata COUNT queries. L8Query WHERE clauses convert to SQL automatically.

Testing

Coverage includes PostgreSQL CRUD (POST, PUT, DELETE), PATCH/partial update, service mesh integration, object-relational conversion, write-through cache with database pre-loading, missing/empty table handling, and TSDB write/read/time-range queries.