connect-sqlite3
Advanced tools
Comparing version
@@ -0,1 +1,14 @@ | ||
0.9.0 / 2012-09-11 | ||
================== | ||
- re-wrote unit tests with Mocha and Should.js | ||
- added option param for db file name (seperate from table name) | ||
- merged pull request from Nibbler999 (added support for returning undefined for unknown sessions) | ||
- updated readme | ||
0.8.0 / 2012-09-10 | ||
================== | ||
- forked previous lib | ||
- swapped out sqlite lib for node-sqlite3 | ||
- made sure existing unit tests work | ||
0.0.1 / 2011-09-24 | ||
@@ -2,0 +15,0 @@ ================== |
@@ -12,4 +12,4 @@ /* | ||
var sqlite3 = require('sqlite3'); | ||
var events = require('events'); | ||
var sqlite3 = require('sqlite3'), | ||
events = require('events'); | ||
@@ -32,59 +32,65 @@ /** | ||
/** | ||
* Connect's Store. | ||
*/ | ||
/** | ||
* Connect's Store. | ||
*/ | ||
var Store = connect.session.Store; | ||
var Store = connect.session.Store; | ||
/** | ||
* Initialize SQLiteStore with the given `options`. | ||
* | ||
* @param {Object} options | ||
* @api public | ||
*/ | ||
/** | ||
* Initialize SQLiteStore with the given options. | ||
* | ||
* @param {Object} options | ||
* @api public | ||
*/ | ||
function SQLiteStore(options) { | ||
options = options || {}; | ||
Store.call(this, options); | ||
function SQLiteStore(options) { | ||
options = options || {}; | ||
Store.call(this, options); | ||
this.table = options.db || 'sessions'; | ||
var dbFile = (options.dir || '.') + '/' + this.table + '.db'; | ||
this.table = options.table || 'sessions'; | ||
this.db = options.db || this.table; | ||
var dbPath; | ||
this.db = new sqlite3.Database(dbFile); | ||
this.client = new events.EventEmitter(); | ||
var self = this; | ||
if(this.db !== ':memory:') { | ||
dbPath = (options.dir || '.') + '/' + this.db + '.db'; | ||
} else { | ||
dbPath = this.db; | ||
} | ||
this.db = new sqlite3.Database(dbPath); | ||
this.client = new events.EventEmitter(); | ||
var self = this; | ||
this.db.exec('CREATE TABLE IF NOT EXISTS ' + this.table + ' (' + 'sid PRIMARY KEY, ' + 'expired, sess)', | ||
function(err) { | ||
if (err) throw err; | ||
self.client.emit('connect'); | ||
} | ||
); | ||
} | ||
this.db.exec('CREATE TABLE IF NOT EXISTS ' + this.table + ' (' + 'sid PRIMARY KEY, ' + 'expired, sess)', | ||
function(err) { | ||
if (err) throw err; | ||
self.client.emit('connect'); | ||
} | ||
); | ||
} | ||
/** | ||
* Inherit from `Store`. | ||
*/ | ||
/** | ||
* Inherit from Store. | ||
*/ | ||
SQLiteStore.prototype.__proto__ = Store.prototype; | ||
SQLiteStore.prototype.__proto__ = Store.prototype; | ||
/** | ||
* Attempt to fetch session by the given `sid`. | ||
* | ||
* @param {String} sid | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
/** | ||
* Attempt to fetch session by the given sid. | ||
* | ||
* @param {String} sid | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
SQLiteStore.prototype.get = function(sid, fn) { | ||
var now = new Date().getTime(); | ||
this.db.get('SELECT sess FROM ' + this.table + ' WHERE sid = ? AND ? <= expired', [sid, now], | ||
function(err, row) { | ||
if (err) fn(err); | ||
fn(null, JSON.parse(row.sess)); | ||
} | ||
); | ||
}; | ||
SQLiteStore.prototype.get = function(sid, fn) { | ||
var now = new Date().getTime(); | ||
this.db.get('SELECT sess FROM ' + this.table + ' WHERE sid = ? AND ? <= expired', [sid, now], | ||
function(err, row) { | ||
if (err) fn(err); | ||
if (!row) return fn(); | ||
fn(null, JSON.parse(row.sess)); | ||
} | ||
); | ||
}; | ||
@@ -120,45 +126,45 @@ | ||
/** | ||
* Destroy the session associated with the given `sid`. | ||
* | ||
* @param {String} sid | ||
* @api public | ||
*/ | ||
/** | ||
* Destroy the session associated with the given `sid`. | ||
* | ||
* @param {String} sid | ||
* @api public | ||
*/ | ||
SQLiteStore.prototype.destroy = function(sid, fn) { | ||
this.db.run('DELETE FROM ' + this.table + ' WHERE sid = ?', [sid], fn); | ||
}; | ||
SQLiteStore.prototype.destroy = function(sid, fn) { | ||
this.db.run('DELETE FROM ' + this.table + ' WHERE sid = ?', [sid], fn); | ||
}; | ||
/** | ||
* Fetch number of sessions. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
/** | ||
* Fetch number of sessions. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
SQLiteStore.prototype.length = function(fn) { | ||
this.db.all('SELECT COUNT(*) AS count FROM ' + this.table + '', function(err, rows) { | ||
if (err) fn(err); | ||
fn(null, rows[0].count); | ||
}); | ||
}; | ||
SQLiteStore.prototype.length = function(fn) { | ||
this.db.all('SELECT COUNT(*) AS count FROM ' + this.table + '', function(err, rows) { | ||
if (err) fn(err); | ||
fn(null, rows[0].count); | ||
}); | ||
}; | ||
/** | ||
* Clear all sessions. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
/** | ||
* Clear all sessions. | ||
* | ||
* @param {Function} fn | ||
* @api public | ||
*/ | ||
SQLiteStore.prototype.clear = function(fn) { | ||
this.db.exec('DELETE FROM ' + this.table + '', function(err) { | ||
if (err) fn(err); | ||
fn(null, true); | ||
}); | ||
}; | ||
SQLiteStore.prototype.clear = function(fn) { | ||
this.db.exec('DELETE FROM ' + this.table + '', function(err) { | ||
if (err) fn(err); | ||
fn(null, true); | ||
}); | ||
}; | ||
return SQLiteStore; | ||
return SQLiteStore; | ||
}; |
{ | ||
"name": "connect-sqlite3", | ||
"description": "SQLite3 session store for Connect", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"author": "David Feinberg", | ||
@@ -18,3 +18,3 @@ "main": "lib/connect-sqlite3", | ||
"type": "git", | ||
"url": "https://github.com/rawberg/connect-sqlite3.git" | ||
"url": "git://github.com/rawberg/connect-sqlite3.git" | ||
}, | ||
@@ -21,0 +21,0 @@ "licenses": [ |
@@ -0,15 +1,14 @@ | ||
# Connect SQLite3 | ||
# Connect SQLite | ||
connect-sqlite3 is a SQLite3 session store modeled after the TJ's connect-redis store. | ||
connect-sqlite is a SQLite session store, just copied connect-redis. | ||
connect-sqlite support only connect `>= 1.4.0`. | ||
## Installation | ||
$ npm install connect-sqlite | ||
$ npm install connect-sqlite3 | ||
## Options | ||
- `db='sessions'` Database file & table name | ||
- `db='sessions'` Database table name | ||
- `db='sessions'` Database file name (defaults to table name) | ||
- `dir='.'` Direcotry to save '<db>.db' file | ||
@@ -19,4 +18,4 @@ | ||
var connect = require('connect') | ||
, SQLiteStore = require('connect-sqlite')(connect); | ||
var connect = require('connect'), | ||
SQLiteStore = require('connect-sqlite3')(connect); | ||
@@ -30,3 +29,3 @@ connect.createServer( | ||
var SQLiteStore = require('connect-sqlite')(express); | ||
var SQLiteStore = require('connect-sqlite3')(express); | ||
@@ -33,0 +32,0 @@ app.configure(function() { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
101211
1376.67%9
28.57%3991
2154.8%45
-2.17%6
Infinity%1
Infinity%