moonorm

Showcase · Live engine

The library, compiled — not a mock-up.

This page does not re-implement moonorm in JavaScript. It loads the real package compiled to JS and calls its public API. Switch a dialect, flip a toggle, and read the SQL the actual codegen emits.

The model

A Model is built once from a row reader and a row writer. The example below is the exact source the engine on this page was built from.

SourceModel::new
MoonBit
Model::new(
  "accounts",
  [
    column("id", BigIntType,
      primary_key=true, autoincrement=true),
    column("email", TextType,
      nullable=false, unique=true),
    column("balance", RealType),
    column("team_id", BigIntType,
      references=("teams", "id"),
      on_delete="SET NULL"),
    column("status", TextType,
      nullable=false, default="'active'"),
    column("level", IntType,
      checks=["level >= 0"]),
  ],
  from_row, to_row,
)
What it means
A table "accounts" with six columns.
id      → primary key, auto increment
email   → not null, unique
balance → nullable real
team_id → fk → teams(id), SET NULL
status  → not null, default 'active'
level   → integer, checked >= 0

Generate DDL — pick a dialect

One model, three dialects. The buttons call create_table_sql_for(dialect) on the loaded engine.

Engine callcreate_table_sql_for

        

Build a query

The same engine builds a parameterized SELECT. Toggle clauses and read the SQL plus its bound parameters.

Engine callSelect::build

        

Provenance. This page loads engine/moonorm.js — the moonorm package compiled to JavaScript with moon build --target js. It is rebuilt by the docs workflow whenever the library changes, so the output you read here is always the library's own. No SQL on this page is hand-authored.

Read the guide Browse the API