OpenSya Persistence

Build your persistence layer around your domain, not your database.

OpenSya Persistence turns table metadata into a strongly typed Query Engine and a consistent runtime for validation, relations, lifecycle hooks, transactions, audit logs and domain events.

Framework-agnostic and adapter-based, it gives TypeScript applications a stable persistence API while keeping the underlying database replaceable. It powers OpenSya, but is designed for any TypeScript project.

Getting started
Define a typed table and execute your first PostgreSQL query.
Metadata and inference
Model tables once and infer every returned entity automatically.
Query Engine
Read and mutate data through the validated execution runtime.

Runtime features

Validation
Structural, field and cross-field rules.
Relations
Explicit batched population for every cardinality.
Field visibility
Keep secrets and contextual fields out of results.
Audit Log
Record transactional before/after snapshots and changes.
Domain Events
Persist typed events atomically and publish them safely.
Cursor pagination
Stable keyset pagination without OFFSET.

What it owns

  • a typed metadata registry and schema validation;
  • a database-independent query model;
  • inferred result types from table metadata;
  • safe, transactional mutations and lifecycle hooks;
  • explicit relation population and result serialization;
  • transactional audit logs and domain-event outboxes;
  • deterministic schema migrations and ordered migration artifacts;
  • PostgreSQL execution and introspection through Drizzle.
Persistence generates database-neutral migration artifacts and currently executes them through PostgreAdapter. It uses Drizzle internally for the PostgreSQL adapter without making Drizzle part of the application-facing API.