Installation
You can get the latest version of CouchbaseODM
via NPM
.
$ npm install kouchbase-odm --save
Connection setup
CouchbaseODM will keep track on all of your defined models so you should ideally only create one CouchbaseODM instance.
const couchbaseODM = require('kouchbase-odm');
const couchbaseSDK = require('couchbase');
const cluster = new couchbaseSDK.Cluster('couchbase://127.0.0.1');
const bucket = cluster.openBucket('bucket-name');
//as simple as that
const couchbase = new couchbaseODM({
bucket: bucket
});
The CouchbaseODM constructor can accept quite amount of options. Detailed description of them is available via the API reference
The constructor options will be used as default options for all defined models.
Your first Model
A Model is defined by couchbase.define('name', {/*schema definition*/}, {/*options*/})
const User = couchbase.define('User', {
type: 'object',
properties: {
username: {type: 'string'},
email : {type: 'string'},
}
}, {
//options
timestamps: true
});
Other model's options can be found in the Model API reference
For detailed description of Model schema definition, continue with Model schema definition