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',
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 ] );
console.log( obj[ key ] );
});
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 ) {
});
Deletion
ctx.set( 'delMe', 'foo' )
.then(function() {
return ctx.get( 'delMe' );
}).then(function( obj ) {
console.log( obj );
return ctx.del( 'delMe' );
}).then(function() {
return ctx.get( 'delMe' );
}).then(function( item ) {
console.log( item );
});
Key Expiration
ctx.set( 'beep', 'boop', 2000 )
.then(function(){
setTimeout(function(){
ctx.get( 'beep' )
.then(function( item ) {
console.log( item );
});
}, 4000);
});
Tests
Create your test PostgresSQL database and user
$ createuser myApp
$ createdb myApp
$ npm test