Introduction
Ottoman needs to be bound to a bucket, so in the first step we assign the existing bucket to it based on the cb.js file. Easiest would be to expose Ottoman via the cb.js module.
The idea is to create one file per model in a models subfolder:
Ottoman-Model
- Create an ottoman model, this can be an extra generator 'ottoman-model':
Here an example:
var Furniture = ottoman.model('Furniture', {
name: 'string'
});
The following properties are relevant
- Name of the model?
- File name of the model?
- Repeat:
- Property name?
- Property type ['string', 'number', 'integer', 'boolean', 'Date', array('string'),...,'Custom']? (Including type validation!)
- If 'Custom' type
- To which custom type do you want to refer? (List them!, realize as reference by default!)
- Should this property be validated?
- Create a simple validator function out of the box for a validated property, e.g.:
function validate${PropName}(val) {
var expr = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
if(val && !val.match(expr)) {
throw new Error('The property value ' + ${PropName} + ' is not valid!');
}
}
- Do you want to create an index for this property?
- Which type should the index have ['refdoc', 'view', 'n1ql'](Ensure indexes!)
- Do you want to create a query for the model
- What's the query name?
- Of model type?
- By property?
ottoman.model('Post', {
user: {ref:'User'},
title: 'string',
body: 'string'
});
ottoman.model('User', {
name: 'string'
}, {
queries: {
myPosts: {
of: 'Post',
by: 'user'
}
}
});
Ottoman-Example
Create an example instance for the model, e.g.:
- For which model would you create an example? (List them!)
- Name of the example file?
var Account = ottoman.model('Account', {
email: 'string',
name: 'string'
});
ottoman.model('User', {
username: 'string',
account: Account
});
Ottoman-Express-Route
Create in order to access entities of this model. So basically a CRUD service for it by reflecting the references to other Models.
Ottoman-UI
Create UI forms (Search, Master-Detail, List, ...) based on the model by also reflecting the references to other Models.
Introduction
Ottoman needs to be bound to a bucket, so in the first step we assign the existing bucket to it based on the cb.js file. Easiest would be to expose Ottoman via the cb.js module.
The idea is to create one file per model in a models subfolder:
Ottoman-Model
Here an example:
The following properties are relevant
Ottoman-Example
Create an example instance for the model, e.g.:
Ottoman-Express-Route
Create in order to access entities of this model. So basically a CRUD service for it by reflecting the references to other Models.
Ottoman-UI
Create UI forms (Search, Master-Detail, List, ...) based on the model by also reflecting the references to other Models.