Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

connect-pg-simple

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-pg-simple - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

13

index.js

@@ -14,2 +14,3 @@ var oneDay = 86400;

this.tableName = options.tableName || 'session';
this.conString = options.conString || process.env.DATABASE_URL;

@@ -63,9 +64,9 @@ this.ttl = options.ttl;

if (Math.random() < 0.05) {
this.query('DELETE FROM session WHERE expire < NOW()');
this.query('DELETE FROM "' + this.tableName + '" WHERE expire < NOW()');
}
this.query('SELECT sess FROM session WHERE sid = $1 AND expire >= NOW()', [sid], function (err, data) {
this.query('SELECT sess FROM "' + this.tableName + '" WHERE sid = $1 AND expire >= NOW()', [sid], function (err, data) {
if (err) return fn(err);
if (!data) return fn();
try {
return fn(null, ("string" == typeof data.sess) ? JSON.parse(data.sess) : data.sess);
return fn(null, ('string' === typeof data.sess) ? JSON.parse(data.sess) : data.sess);
} catch(e) {

@@ -96,5 +97,5 @@ return this.destroy(sid, fn);

this.query("UPDATE session SET sess = $1, expire = to_timestamp($2) WHERE sid = $3 RETURNING sid", [sess, ttl, sid], function (err, data) {
this.query('UPDATE "' + this.tableName + '" SET sess = $1, expire = to_timestamp($2) WHERE sid = $3 RETURNING sid', [sess, ttl, sid], function (err, data) {
if (!err && data === false) {
self.query("INSERT INTO session (sess, expire, sid) SELECT $1, to_timestamp($2), $3 WHERE NOT EXISTS (SELECT 1 FROM session WHERE sid = $4)", [sess, ttl, sid, sid], function (err) {
self.query('INSERT INTO "' + this.tableName + '" (sess, expire, sid) SELECT $1, to_timestamp($2), $3 WHERE NOT EXISTS (SELECT 1 FROM session WHERE sid = $4)', [sess, ttl, sid, sid], function (err) {
fn && fn.apply(this, err);

@@ -116,3 +117,3 @@ });

PGStore.prototype.destroy = function (sid, fn) {
this.query("DELETE FROM session WHERE sid = $1", [sid], function (err) {
this.query('DELETE FROM "' + this.tableName + '" WHERE sid = $1', [sid], function (err) {
fn && fn(err);

@@ -119,0 +120,0 @@ });

{
"name": "connect-pg-simple",
"version": "2.0.0",
"version": "2.1.0",
"description": "A simple, minimal PostgreSQL session store for Connect/Express",

@@ -5,0 +5,0 @@ "url": "http://github.com/voxpelli/node-connect-pg-simple",

@@ -45,3 +45,4 @@ # Connect PG Simple

pg : pg,
conString : process.env.FOO_DATABASE_URL
conString : process.env.FOO_DATABASE_URL,
tableName : 'user_sessions'
}),

@@ -70,5 +71,10 @@ secret: process.env.FOO_COOKIE_SECRET,

* **conString** - if you don't have your PostgreSQL connection string in the `DATABASE_URL` environment variable (as you do by default on eg. Heroku) – then you need to specify the connection [string or object](https://github.com/brianc/node-postgres/wiki/pg#connectstring-connectionstring-function-callback) here so that this module that create new connections. Needen even if you supply your own database module.
* **tableName** - if your session table is named something else than `session`, then you can specify that here.
## Changelog
### 2.1.0
* Enable the table name to be configured through new `tableName` option
### 2.0.0

@@ -75,0 +81,0 @@

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