Package Exports
- openrecord
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (openrecord) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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!
Installation
npm install openrecord
Documentation
Features
- SQLite3, MySQL, Postgres, REST support
- Async schema definition: You could even change your model definition temporarily
- 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
orcreator_id
- paranoid: Soft delete of records
- nested set: Build trees easily
- sorted list: Don't worry about lists
- stampable: automatically set
- ... with more than 1000 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.