orm

module
v0.0.0-...-7e51de9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2026 License: MIT

README

orm 0.0.1

A schema-driven model query grammar for Go, PHP, Rust, and TypeScript. Version 0.0.1. The target syntax is specified in docs/dsl.md and the work order in docs/plan.md.

$battles = (new Battle)->connect($slave1)->serviceSeq(7)->andIsClose(false)
    ->and(fn (Battle $q) => $q->isDisplay(true)->or()->isAllday(true))
    ->relation((new User)->matchUserSeqWithSeq())->orderBySeqDesc()->limit(0, 20)->gets();
battles, err := model.Battle().Connect(slave1).ServiceSeq(7).AndIsClose(false).
    And(func(q *model.BattleModel) { q.IsDisplay(true).Or().IsAllday(true) }).
    Relation(model.User().MatchUserSeqWithSeq()).OrderBySeqDesc().Limit(0, 20).Gets()
let battles = Battle::new().connect(&slave1).service_seq(7).and_is_close(false)
    .and(|q| q.is_display(true).or().is_allday(true))
    .relation(User::new().match_user_seq_with_seq()).order_by_seq_desc().limit(0, 20).gets().await?;
const battles = await new Battle().connect(slave1).serviceSeq(7).andIsClose(false)
    .and(q => q.isDisplay(true).or().isAllday(true))
    .relation(new User().matchUserSeqWithSeq()).orderBySeqDesc().limit(0, 20).gets();

The four chains produce the same SQL, binds, and results. tests/conformance checks the common vectors on MySQL, PostgreSQL, and SQLite.

Finders accept any column chain after By:

$battles = (new Battle)->connect($slave1)->getsByServiceSeqAndIsClose(7, false);
battles, err := model.Battle().Connect(slave1).GetsByServiceSeqAndIsClose(7, false)
let battles = Battle::new().connect(&slave1).gets_by_service_seq_and_is_close(7, false).await?;
const battles = await new Battle().connect(slave1).getsByServiceSeqAndIsClose(7, false);

get returns one row or null, gets returns a collection, and getCount returns a count. A model receives its database connection through connect; inside connection.transaction(fn), a model without connect uses the active transaction. Relation children use the parent connection unless they call connect. A model without a connection outside a transaction returns CONFIG.

How it works

  • Schema: one hand-written Mermaid erDiagram (schema/*.mmd) → ormgen buildschema.json (manifest with schema_hash).
  • Models: each language generates its models with its own build tool: go generate (Go), vendor/bin/orm-gen (PHP), the orm-gen npm bin in npm run build (TypeScript), and the orm-build crate in build.rs (Rust).
  • Runtime: the client library validates each statement shape against schema.json, assembles the SQL in the application process, caches the plan, and executes it through the language-native driver. No service, daemon, or extension runs beside the application.
  • Databases: MySQL 8, PostgreSQL 12+, and SQLite 3.46+ use the same request and result rules (docs/dialects.md).
  • Equality: tests/conformance runs the same vectors in the four clients and compares the SQL, binds, and results.

Quick start (MySQL 8.x, local socket)

mysql -uroot orm_bench < bench/sql/battle.sql
mysql -uroot orm_bench < bench/sql/seed.mysql.sql                  # schema + 100k rows
go run ./bench/seedaes -driver mysql -dsn 'root@unix(/tmp/mysql.sock)/orm_bench'
go run ./cmd/ormgen build schema/bench.mmd --out schema/schema.json
(cd clients/go/model && go generate)                                # Go models
php clients/php/bin/orm-gen gen --schema schema/schema.json --out clients/php/gen --namespace 'App\Orm'
(cd clients/typescript && npm run build)                            # TypeScript models and library
(cd clients/rust && cargo build --release)                          # build.rs generates the Rust models
go test ./...
npm run typescript:test
(cd clients/rust && cargo test --workspace)
go run ./tests/conformance/check run -driver mysql                  # compares the four clients

Documents

Online documentation — static guides, interface diagrams and implementation status, built from docs/ and deployed through GitHub Pages.

한국어 README

공통 인터페이스 · 구현 대조표 · 자동 검사 — 자료구조·수명·공개 API와 검증 상태.

docs/usage.md — start here: schema, generation, connecting, querying, writing, relations, the three databases, operations.

Security · Contributing · Code of Conduct · Changelog

examples/thin-slice · examples/complex · docs/dsl.md grammar · docs/schema.md Mermaid dialect, import, validate · docs/protocol.md IR/Plan · docs/codec.md column styles · docs/dialects.md MySQL/PostgreSQL/SQLite · docs/errors.yaml codes · docs/perf.md measurements and gates · docs/checklist.md work plan.

Tooling

ormgen build | gen --lang go | import --dsn | validate --dsn | ddl --dialect | diff | errors --lang, vendor/bin/orm-gen gen | build | import | validate | ddl | diff | migrate (PHP), orm-gen (TypeScript), orm-build (Rust), tests/conformance/check run|compare|record.

License

MIT — see LICENSE.

Directories

Path Synopsis
bench
seedaes command
seedaes fills the AES columns of the bench battle table on PostgreSQL and SQLite with the authenticated host format used by every client.
seedaes fills the AES columns of the bench battle table on PostgreSQL and SQLite with the authenticated host format used by every client.
clients
go/model
Package model holds the Go models generated from schema/schema.json for the repository's tests, examples, and benchmarks.
Package model holds the Go models generated from schema/schema.json for the repository's tests, examples, and benchmarks.
go/orm
Package orm is the Go client runtime.
Package orm is the Go client runtime.
go/orm/pg
Package pg registers the PostgreSQL driver with the executor.
Package pg registers the PostgreSQL driver with the executor.
go/orm/sqlite
Package sqlite registers the SQLite driver with the executor.
Package sqlite registers the SQLite driver with the executor.
cmd
ormgen command
Package contracts loads the common interface manifest, validates its native adapters, and generates the component documents from it.
Package contracts loads the common interface manifest, validates its native adapters, and generates the component documents from it.
Package engine is the query planner: IR in, Plan out.
Package engine is the query planner: IR in, Plan out.
dialect
Package dialect renders the database-specific pieces of SQL.
Package dialect renders the database-specific pieces of SQL.
ir
Package ir defines the wire form clients send (JSON, docs/protocol.md) and validates it against the manifest.
Package ir defines the wire form clients send (JSON, docs/protocol.md) and validates it against the manifest.
plan
Package plan is what executors run: SQL text with bind slots and an assembly spec.
Package plan is what executors run: SQL text with bind slots and an assembly spec.
planner
Package planner turns a validated IR request into a Plan.
Package planner turns a validated IR request into a Plan.
schema
Package schema turns the hand-written Mermaid erDiagram (docs/schema.md) into the manifest the engine and generators consume.
Package schema turns the hand-written Mermaid erDiagram (docs/schema.md) into the manifest the engine and generators consume.
examples
complex/go command
A complex statement in every client language, one JSON document.
A complex statement in every client language, one JSON document.
thin-slice/go command
Thin-slice demo (Go): one statement in every client language, one JSON.
Thin-slice demo (Go): one statement in every client language, one JSON.
Package generator exposes the Go model generator to other programs.
Package generator exposes the Go model generator to other programs.
internal
ormgen
ormgen ddl: manifest → CREATE TABLE statements for one dialect (docs/dialects.md).
ormgen ddl: manifest → CREATE TABLE statements for one dialect (docs/dialects.md).
tests
conformance/check command
Conformance checker: runs the client runners (or reads their outputs) and compares each vector's statements and result against tests/conformance/vectors.json after canonicalizing the JSON (sorted keys, shortest numbers).
Conformance checker: runs the client runners (or reads their outputs) and compares each vector's statements and result against tests/conformance/vectors.json after canonicalizing the JSON (sorted keys, shortest numbers).
conformance/runner_go command
Conformance runner (Go).
Conformance runner (Go).
interfaces/check command
Interface checks compare native declarations to a reviewed symbol manifest and enforce common method contracts independently of the generated source.
Interface checks compare native declarations to a reviewed symbol manifest and enforce common method contracts independently of the generated source.
schema/record command
Records the schema tool results that every language's schema tools must reproduce: the manifest, the DDL of each dialect, the migration between manifests, and the migration plan file, for the Mermaid fixtures of the Go tests of the client, the engine, and the tools, and the bench schema.
Records the schema tool results that every language's schema tools must reproduce: the manifest, the DDL of each dialect, the migration between manifests, and the migration plan file, for the Mermaid fixtures of the Go tests of the client, the engine, and the tools, and the bench schema.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL