fogine/couchbase-odm

View on GitHub
tutorials/1.gettingStarted.md

Summary

Maintainability
Test Coverage
Installation
---------------

You can get the latest version of `CouchbaseODM` via `NPM`.  

````bash
$ 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.  

````javascript
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 {@link CouchbaseODM 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*/})`


````javascript
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  {@link Model Model API reference}  

For detailed description of Model schema definition, continue with {@tutorial 2.schemaDefinitionGuide}