sofa-odm

0.1.8 • Public • Published

Sofa the Couchbase ODM

This project is a driver for the NodeJS NoSQL ODM, visit this repository for further informations.

Current version: [v/0.1.8][dist]

Build Status Dependency Status Coverage Status

Getting started

npm install sofa-odm --save

Sample code

var sofa = require('sofa-odm');
var session = new sofa();
// handles all errors
session.on('error', function(err) {
  console.error(err);
});
// declare a user mapper attached to current session
var users = session.declare('user', {
  // declare properties
  properties: {
    name: {
      type: 'string',       // data type : string, number, boolean, array, object
      validate: [4, 64]     // validators, depends on data type
    },
    email: {
      type: 'string',
      validate: /S+@S+\.S+/,
      unique: true
    },
    password: {
      type: 'string',
      validate: [6, 24]
    }
  }
});
// connect to couchbase
session.connect({
  // connection parameters
  host: 'localhost:8091',
  bucket: 'default'
}).then(function() {
  // creates a new entry
  var john = users.create({
    name: 'John Doe',
    email: 'john@doe.com',
    password: 'secret'
  });
  // saves the active record
  john.save()
    // use a email view to find the user
    .then(function() {
      return users.find('email', 'john@doe.com');
    })
    // deletes the first found record
    .then(function(result) {
      return result.rows[0].remove();
    })
    .done()
  ;
}).done();

Misc

This code is distribute under The MIT License (MIT), authored by Ioan CHIRIAC.

Readme

Keywords

Package Sidebar

Install

npm i sofa-odm

Weekly Downloads

0

Version

0.1.8

License

MIT

Last publish

Collaborators

  • ichiriac