loopback-datasource-juggler/examples/app.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

2013-05-24 05:20:20 +00:00
var ModelBuilder = require('../../jugglingdb').ModelBuilder;
var modelBuilder = new ModelBuilder();
// define models
2013-05-24 05:20:20 +00:00
var Post = modelBuilder.define('Post', {
title: { type: String, length: 255 },
2013-05-24 05:20:20 +00:00
content: { type: ModelBuilder.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-24 05:20:20 +00:00
var User = modelBuilder.define('User', {
name: String,
2013-05-24 05:20:20 +00:00
bio: ModelBuilder.Text,
approved: Boolean,
joinedAt: Date,
age: Number
});
2013-05-28 20:50:59 +00:00
var Group = modelBuilder.define('Group', {group: 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-24 05:20:20 +00:00
console.log(modelBuilder.models);
console.log(modelBuilder.definitions);
2013-05-28 20:50:59 +00:00
User.mixin(Group);
var user = new User({name: 'Ray', group: 'Admin'});
console.log(user);