Socket
Socket
Sign inDemoInstall

kevin-johnson

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kevin-johnson

PostgresSQL backed key/val store with support for JSON values, key expiration and in memory caching


Version published
Weekly downloads
9
increased by350%
Maintainers
1
Weekly downloads
 
Created
Source

PostgresSQL Context

Essentially hstore with JSON val and key expiration support

npm install kevin-johnson --save

var appCtx = require( 'kevin-johnson' );
var opts = {
  appName: 'myApp', // used with for database
  // postgres connection info. uses defaults based on appName
  database: {
    host: 'localhost',
    port: 5432,
    user: 'myApp',
    name: 'myApp'
  }
};
var key = 'key';
var val = 'val';

appCtx( opts ).then(function( ctx ){
  return ctx.set( key, val );
})
.then(function( obj ){
  var keys = Object.keys( obj );
  console.log( keys[ 0 ] );  // 'key'
  console.log( obj[ key ] ); // 'val'
});

Batch setting/getting

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

Deletion

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

Key Expiration

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

Tests

Create your test PostgresSQL database and user

$ createuser myApp
$ createdb myApp
$ npm test

FAQs

Package last updated on 02 Oct 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc