data-hopper

1.0.0 • Public • Published

data-hopper

NPM Version

About

It's not uncommon on a project to have multiple datastores. This project makes it easy to store all your datastore connections in one easy accessible place. A number of drivers are builtin by default to support the most popular datastores.

Install

npm install data-hopper

Drivers

  • Elasticsearch
  • Mongodb
  • MySql
  • Postgres
  • Redis
  • Sqlite

Example

'use strict';
 
const DataHopper = require('data-hopper');
 
const hopper = DataHopper();
 
/**
 * Name connection and pass in the config
 */
hopper.load('kittens', {
  driver: 'sqlite',
  filename: __dirname + './meow.sqlite'
});
 
// Get the connection off the hopper
const kittens = hopper.get('kittens');
 
kittens.schema.createTableIfNotExists('meows', function(table) {
  table.increments('id');
  table.string('name');
}).then(function() {
  return kittens.insert({name: 'Fluffy'}).into('meows');
});
 
console.log(hopper.info('cache'));

Adding drivers is quite trivial, below is an example with the npm module nedb

'use strict';
 
const Nedb       = require('nedb');
const DataHopper = require('data-hopper');
 
const hopper = DataHopper();
 
hopper.useDriver({
  label: 'nedb',
  configure(config) {
    config = config || {};
    config.autoload = true;
    return config;
  },
  start(config) {
    return new Nedb(config);
  }
});
 
hopper.load('blog', {
  driver: 'nedb',
  timestampData: true
});

/data-hopper/

    Package Sidebar

    Install

    npm i data-hopper

    Weekly Downloads

    2

    Version

    1.0.0

    License

    none

    Last publish

    Collaborators

    • rezen