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#

BuilderPostgreSQLMySQLSQLiteJS type
integer()INTEGERINTINTEGERnumber
bigint()BIGINTBIGINTINTEGERnumber
float()REALFLOATREALnumber
decimal()DECIMALDECIMALREALnumber
string()VARCHAR(255)VARCHAR(255)TEXTstring
text()TEXTTEXTTEXTstring
mediumtext()TEXTMEDIUMTEXTTEXTstring
longtext()TEXTLONGTEXTTEXTstring
boolean()BOOLEANTINYINT(1)INTEGERboolean
date()DATEDATETEXTstring
time()TIMETIMETEXTstring
datetime()TIMESTAMPDATETIMETEXTstring
timestamp()TIMESTAMPTIMESTAMPTEXTstring
json()JSONJSONTEXTobject*
uuid()UUIDVARCHAR(36)TEXTstring
binary()BYTEABLOBBLOBBuffer
Note
* Pair json() with a transformer(.set()/.get()) to (de)serialize objects automatically.

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'); }