MasterRecord
Installation
Add the ORM and a database driver to your project.
MasterRecord is a pure-ESM package and requires Node.js 20+. In a Master app it’s already installed in the backend/ workspace — this page is for adding it to any standalone Node project.
Install#
terminal
$ npm install masterrecord
MasterRecord bundles the drivers for all three engines (better-sqlite3, mysql2, and pg), so there is nothing else to install for SQLite, MySQL, or PostgreSQL.
ESM only
Your project must be ESM. Add
"type": "module" to your package.json and use import / export syntax throughout.The migration CLI#
MasterRecord ships a masterrecord binary for migrations. Run it with npx, or through the Master CLI’s friendly master db wrapper:
terminal
$ npx masterrecord --help$ # or, inside a Master app:$ master db migrate
Verify#
Create a context, register a model, and run a query to confirm everything is wired up:
smoke-test.mjs
import context from 'masterrecord/context';
class Widget { id(db) { db.integer().primary().auto(); } name(db) { db.string(); } }
class AppContext extends context {
constructor() {
super();
this.env({ type: 'better-sqlite3', connection: 'db/' });
this.dbset(Widget);
}
}
const db = new AppContext();
console.log('connected:', db.isSQLite); // true