灵活的Node.js ORM框架:stormer

jopen 8年前

灵活的Node.js ORM框架。简化一些任务比如models创建和校验,并从数据库取得和保存实体。

Installation

npm install stormer

Examples

Example 1: Create a store

var store = new Store();

Example 2: Define a new model and its schema

var store = new Store();    var schema = {      firstName: 'String',      age: {          type: 'Number',          required: true      }  };    store.define('myModel', schema);

Example 3: Create and update an item

store.create('myModel', {pk: '1234', firstName: 'George', age: 12}).then(function(instance) {      instance.firstName = 'Rafael';      instance.save().then(function() {          store.get('1234').then(function(instance) {              console.log(instance.firstName); // This prints 'Rafael'          });         });  }); 

Example 4: Store will throw an error if the object doesn't conform with the schema

// Age should be a Number  store.create('myModel', {pk: '1234', firstName: 'George', age: '12'}).catch(function(err) {      //Catch a validation error here  }); 

项目主页:http://www.open-open.com/lib/view/home/1445517392085