MasterRecord
Field Types
One portable type vocabulary across three databases.
MasterRecord resolves each builder type to the right native column on every engine, so the same model runs unchanged on SQLite, MySQL, and PostgreSQL.
Reference table#
| Builder | PostgreSQL | MySQL | SQLite | JS type |
|---|---|---|---|---|
integer() | INTEGER | INT | INTEGER | number |
bigint() | BIGINT | BIGINT | INTEGER | number |
float() | REAL | FLOAT | REAL | number |
decimal() | DECIMAL | DECIMAL | REAL | number |
string() | VARCHAR(255) | VARCHAR(255) | TEXT | string |
text() | TEXT | TEXT | TEXT | string |
mediumtext() | TEXT | MEDIUMTEXT | TEXT | string |
longtext() | TEXT | LONGTEXT | TEXT | string |
boolean() | BOOLEAN | TINYINT(1) | INTEGER | boolean |
date() | DATE | DATE | TEXT | string |
time() | TIME | TIME | TEXT | string |
datetime() | TIMESTAMP | DATETIME | TEXT | string |
timestamp() | TIMESTAMP | TIMESTAMP | TEXT | string |
json() | JSON | JSON | TEXT | object* |
uuid() | UUID | VARCHAR(36) | TEXT | string |
binary() | BYTEA | BLOB | BLOB | Buffer |
Note
Boolean handling#
On SQLite and MySQL there is no native boolean, so MasterRecord stores 1/0 and converts back to real true/false in JavaScript — you always work with booleans.
Dates & times#
Date/time columns map to native types on MySQL/Postgres and to TEXT on SQLite. Store ISO-8601 strings (or set them in a lifecycle hook) for portable behavior:
timestamps.js
export default class Post {
id(db) { db.integer().primary().auto(); }
published_at(db) { db.datetime(); }
beforeSave() {
if (this.__state === 'insert') this.published_at = new Date().toISOString();
}
}The generic escape hatch#
Need a type not listed? Use db.type(name, size) directly:
javascript
price(db) { db.type('numeric', '10,2'); }