kevin-johnson

0.3.0 • Public • Published

PostgresSQL Context

Essentially hstore with JSON val and key expiration support

npm install kevin-johnson

const appStore = require('kevin-johnson');
const opts = {
  appName: 'myApp',
  dbUrl: process.env.DATABASE_URL
};
const key = 'key';
const val = 'val';
 
appStore(opts).then((ctx) => {
  return store.set(key, val);
})
.then((obj) => {
  const keys = Object.keys(obj);
  console.log(keys[ 0 ]);  // 'key'
  console.log(obj[ key ]); // 'val'
});

Batch setting/getting

const items = {
  foo: 'bar',
  ping: {
    beep: [ 'boop', 'bop' ]
  }
};
store.setAll(items)
  .then(() => {
    return store.getAll(Object.keys(items));
  })
  .then(function(map) {
    // map === items
  });

Deletion

store.set('delMe', 'foo')
  .then(() => {
    return store.get('delMe');
  }).then((obj) => {
    console.log(obj); // { delMe: 'foo' }
    return store.del('delMe');
  }).then(() => {
    return store.get('delMe');
  }).then(function(item) {
    console.log(item); // undefined
  });

Key Expiration

store.set('beep', 'boop', 2000)
  .then(() => {
    setTimeout(() => {
      store.get('beep')
        .then((item) => {
          console.log(item); // undefined
        });
    }, 4000);
  });

Tests

Create your test PostgresSQL database and user and create a test.env file for environment constiables

$ createuser myApp
$ createdb myApp
$ echo "DATABASE_URL=postgres://myApp:Ffoodk@localhost:5432/myApp" >> test/test.env
$ echo "NODE_ENV=test" >> test/test.env
$ echo "APP_NAME=appName" >> test/test.env
$ npm test

Readme

Keywords

none

Package Sidebar

Install

npm i kevin-johnson

Weekly Downloads

1

Version

0.3.0

License

MIT

Last publish

Collaborators

  • istrategylabs