convergence

## Install

No longer supported
Last updated 3 years ago by jartmez .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install convergence 
SYNC missed versions from official npm registry.

Convergence

Install

npm install --save convergence

First a little bit of dream code.

A practical use case says more than a 1000 words!

Lets declare an employee model, this gateway will define a typed schema and return a collection of functions to operate on the underlying store such as find, findOne, update, insert, upsert.

const {types, defineModel, engines} = require('convergence');

const store = {};
const engine = engines.memory(store);
const collection = 'employees';

const EmployeeModel = () => {
  const definition = {
    id: types.UUID,
    name: types.STRING,
    lastName: types.STRING,
    job: types.JSON
  };

  return defineModel(Object.assign({}, {engine, collection, definition}));
};

That´s it, now we can call the model methods as we are used to.

const EmployeeModel = require('./../gateways/employee');

EmployeeModel.findOne({where: {id: 'someid'}})
  .then(handleYourSuccessCase)
  .catch(handleErrors);

EmployeeModel.insert({name: 'some name', lastName: 'some last name'})
  .then(handleYourSuccessCase)
  .catch(handleErrors);

The main feature of this Table Gateway lib is that it allows you to change the underlying
database engine seamlessly. Check this implementation.

models/employee.js

const {types, defineModel} = require('convergence');

const collection = 'employees';

const EmployeeModel = engine => {
  const definition = {
    id: types.UUID,
    name: types.STRING,
    lastName: types.STRING,
    job: types.JSON
  };

  return defineModel(Object.assign({}, {engine, collection, definition}));
};

models/users.js

const {types, defineModel} = require('convergence');

const collection = 'users';

const UserModel = engine => {
  const definition = {
    id: types.UUID,
    username: types.STRING,
    email: types.STRING,
    hashedPassword: types.STRING,
    salt: types.JSON
  };

  return defineModel(Object.assign({}, {engine, collection, definition}));
};

Of course we don´t want to be declaring models everywhere, so we can do so in a file dedicated to it.

models/index.js

let models;

const getModels = engine => {
  if (models) return models;

  const UserModel = require('./users')(engine);
  const EmployeeModel = require('./employees')(engine);

  models = {UserModel, EmployeeModel};

  return models;
};

module.exports = getModels;

We use the closure of this file to cache the models, so they will just be created once.

Current Tags

  • 0.1.12                                ...           latest (3 years ago)

13 Versions

  • 0.1.12 [deprecated]           ...           3 years ago
  • 0.1.11 [deprecated]           ...           3 years ago
  • 0.1.10 [deprecated]           ...           4 years ago
  • 0.1.9 [deprecated]           ...           4 years ago
  • 0.1.8 [deprecated]           ...           4 years ago
  • 0.1.7 [deprecated]           ...           4 years ago
  • 0.1.6 [deprecated]           ...           4 years ago
  • 0.1.5 [deprecated]           ...           4 years ago
  • 0.1.4 [deprecated]           ...           4 years ago
  • 0.1.3 [deprecated]           ...           4 years ago
  • 0.1.2 [deprecated]           ...           4 years ago
  • 0.1.1 [deprecated]           ...           4 years ago
  • 0.1.0 [deprecated]           ...           4 years ago
Downloads
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 0
Last Month 0
Dependencies (7)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |