Skip to content

cndreiter/openrecord

 
 

Repository files navigation

OpenRecord

Build Status Coverage Status npm package version Dependency Status

ActiveRecord like ORM for nodejs

There are currently a hand full of ORMs for nodejs available - but there is no one with a nice syntax similar to ActiveRecord (Ruby). OpenRecord will change that!

Installation

npm install openrecord

Features

  • SQLite3, MySQL, Postgres, REST support
  • Async schema definition
  • Automatic field definition loading (SQL)
  • Relations (hasMany, hasOne, belongsTo with through, polymorph)
  • Nested Cascade delete
  • Nested Eager Loading
  • Nested Creates
  • Nested Updates
  • Nested Joins
  • Validations
  • Scopes
  • Before and After Hooks
  • Events
  • Chaining
  • Promises
  • Migrations
  • Plugin support
  • Build in plugins (stampable, paranoid, nested set)
  • ... with almost 900 tests

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

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.

About

Active record like ORM for nodejs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%