MasterRecord

Introduction

The data vault — a code-first ORM with an expressive, type-safe query language.

MasterRecord is the ORM half of Master. You describe your tables as plain classes, it generates and runs migrations, and you query with a fluent, lambda-based language — the same code across SQLite, MySQL, and PostgreSQL.

MasterRecord data vault

Two styles, one ORM#

MasterRecord supports both the Active Record style (entities save themselves — great for getting started) and the Entity Framework style (a change-tracked context with saveChanges() — efficient for batch work). Use whichever fits the moment.

Code-first models#

Each field is a method that receives the schema builder. MasterRecord reads these to build your tables — no separate schema file, no decorators.

Post.js
// app/models/Post.js — fields are methods on the class
export default class Post {
  id(db)    { db.integer().primary().auto(); }
  title(db) { db.string().notNullable(); }
  body(db)  { db.text(); }
  views(db) { db.bigint(); }
  created_at(db) { db.datetime(); }
}
Fields are methods, not properties
Define columns as title(db) { db.string(); }, not this.title = {...}. The builder reads prototype methods; plain instance properties are ignored. See Defining Models.

An expressive query language#

Queries use real JavaScript lambdas with $$ placeholders for safe, parameterized values — no string concatenation, no injection.

query.js
import db from './app/models/db.js';

// Create (Active Record style)
const post = db.Post.new();
post.title = 'By the power of Grayskull';
await post.save();

// Read with a parameterized query
const found = await db.Post
  .where((p) => p.title.like($$), 'By the power%')
  .toList();

// Update
found[0].views = 9000;
await found[0].save();

What’s in the box#