Socket
Socket
Sign inDemoInstall

kevin-johnson

Package Overview
Dependencies
152
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    kevin-johnson

PostgresSQL backed key/val store with support for JSON values and key expiration


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
24.3 MB
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 31 Dec 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc