openrecord

Active record like ORM for nodejs

npm install openrecord
3 downloads in the last day
76 downloads in the last week
206 downloads in the last month

OpenRecord

Build Status Node.ci Coverage Status npm package version Dependency Status

ActiveRecord like ORM for nodejs

Installation

npm install openrecord

Features

  • SQLite3, MySQL and Postgres support
  • Async schema definition
  • Automatic field definition loading
  • Relations (hasMany, hasOne, belongsTo with through)
  • Nested Cascade delete
  • Nested Eager Loading
  • Nested Creates
  • Nested Updates
  • Validations
  • Scopes
  • Before and After Hooks
  • Events
  • Chaining
  • Migrations
  • Plugin support
  • ...

Roadmap to 1.0.0

  • attributes rework
  • better documentation
  • better error handling
  • full multiple primary keys support
  • finish .every() callback issues
  • better postgres support (hstore, ect.)
  • more examples

Usage

var OpenRecord = require('openrecord');

var sqlite = new OpenRecord({
  type: 'sqlite3',
  file: 'test.sqlite'
});


sqlite.Model('User', function(){
  this.hasMany('posts');

  this.scope('active', function(){
    this.where({active: true});
  });
});


sqlite.Model('Post', function(){
  this.belongsTo('user');
});


sql.ready(function(){
  var User = sql.Model('User');

  User.active().where({posts: {title_like:'openrecord' }}).include('posts').exec(function(records){
    console.log(records);
  });
});

Documentation

Contributing

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.

npm loves you