loopback-datasource-juggler/examples/app.js

37 lines
873 B
JavaScript
Raw Normal View History

2013-05-17 17:54:14 +00:00
var ADL = require('../../jugglingdb').ADL;
var adl = new ADL();
// define models
2013-05-17 17:54:14 +00:00
var Post = adl.define('Post', {
title: { type: String, length: 255 },
2013-05-17 17:54:14 +00:00
content: { type: ADL.Text },
date: { type: Date, default: function () { return new Date;} },
timestamp: { type: Number, default: Date.now },
published: { type: Boolean, default: false, index: true }
});
// simplier way to describe model
2013-05-17 17:54:14 +00:00
var User = adl.define('User', {
name: String,
2013-05-17 17:54:14 +00:00
bio: ADL.Text,
approved: Boolean,
joinedAt: Date,
age: Number
});
2013-05-17 17:54:14 +00:00
var Group = adl.define('Group', {name: String});
// define any custom method
User.prototype.getNameAndAge = function () {
return this.name + ', ' + this.age;
};
var user = new User({name: 'Joe'});
console.log(user);
2013-05-17 17:54:14 +00:00
console.log(adl.models);
console.log(adl.definitions);