Active record like ORM for nodejs

A hackable, ActiveRecord-like ORM for nodejs

There are currently a hand full of nodejs ORMs available - but there is no one with a nice syntax similar to ActiveRecord (Ruby). OpenRecord has a nice syntax, a ton of features, over 1000 unit tests and could be extended easily!

npm install openrecord


  • SQLite3, MySQL, Postgres, REST and LDAP (+ ActiveDirectory) support
  • Async schema definition: You could even change your model definition temporarily
  • Optional Fibers support
  • Automatic field definition loading (SQL): You don't need to define your database fields twice! OpenRerecord will automatically load your schema definition
  • Relations (hasMany, hasOne, belongsTo with through, polymorph, cross-store)
  • Nested Cascade delete
  • Nested Eager Loading
  • Nested Creates
  • Nested Updates
  • Nested Joins
  • Validations
  • Scopes: Makro like methods
  • Before and After Hooks: For validation, find, create, update, destroy and some more...
  • Events
  • Chaining: Everything is chainable!
  • Promises
  • Migrations: SQL Migrations are build in
  • Plugin support: In fact 99% of OpenRecord is a plugin
  • Build-In SQL plugins:
    • stampable: automatically set created_at, updated_at, updater_id or creator_id
    • paranoid: Soft delete of records
    • nested set: Build trees easily
    • sorted list: Don't worry about lists
  • ... with more than 1200 tests
var OpenRecord = require('openrecord');
var sqlite = new OpenRecord({
  type: 'sqlite3',
  file: 'test.sqlite'
sqlite.Model('User', function(){
  this.scope('active', function(){
    this.where({active: true});
sqlite.Model('Post', function(){
  var User = sqlite.Model('User');{posts: {title_like:'openrecord' }}).include('posts').exec(function(records){


sqlite.Model('User', function(){
    //send email 

Synchronous (via fibers)

  var user = User.find(1).exec(); = false;;

Cross store relations

var sqlite = new OpenRecord({
  type: 'sqlite3',
  file: 'test.sqlite',
  global: true, //expose all Models as globals (default: false) 
  name: 'sqlite'
rest = new OpenRecord({
  type: 'rest',
  url: '',
  name: 'rest'
sqlite.Model('Book', function(){
  this.belongsTo('author', {store: 'rest'});
rest.Model('Author', function(){
  this.hasMany('books', {store: 'sqlite'});

If you've found a bug please report it via the issues page. Please make sure to add a unit test with the bug report! Before submit pull request make sure all tests still passed.