靈活的Node.js ORM框架:stormer
靈活的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 });
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!