connect-orm
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -0,1 +1,6 @@ | ||
connect-orm (0.1.0) | ||
=================== | ||
* add support for express 4. Stay compatible with express 3. | ||
connect-orm (0.0.2) | ||
@@ -2,0 +7,0 @@ =================== |
26
index.js
/*! | ||
* connect-orm | ||
* Copyright 2013 Jérémy Lal <kapouer@melix.org> | ||
* Copyright 2013-2014 Jérémy Lal <kapouer@melix.org> | ||
* MIT Licensed, see LICENSE file | ||
@@ -18,8 +18,8 @@ */ | ||
module.exports = function(connect) { | ||
module.exports = function(session) { | ||
"use strict"; | ||
var ConnectStore = connect.session.Store; | ||
var Store = session.Store || session.session && session.session.Store; | ||
/** | ||
* Initialize Store with the given `options`. | ||
* Initialize OrmStore with the given `options`. | ||
* | ||
@@ -31,5 +31,5 @@ * @param {ORM} db | ||
function Store(db, options) { | ||
function OrmStore(db, options) { | ||
options = options || {}; | ||
ConnectStore.call(this, options); | ||
Store.call(this, options); | ||
this.maxAge = options.maxAge || defaults.maxAge; | ||
@@ -62,3 +62,3 @@ var Session = this.Session = db.define('Session', { | ||
require('util').inherits(Store, ConnectStore); | ||
require('util').inherits(OrmStore, Store); | ||
@@ -73,3 +73,3 @@ /** | ||
Store.prototype.get = function(sid, callback) { | ||
OrmStore.prototype.get = function(sid, callback) { | ||
callback = callback || noop; | ||
@@ -96,3 +96,3 @@ this.Session.one({sid: sid}, function(err, session) { | ||
Store.prototype.set = function(sid, session, callback) { | ||
OrmStore.prototype.set = function(sid, session, callback) { | ||
callback = callback || noop; | ||
@@ -131,3 +131,3 @@ var s = { | ||
Store.prototype.destroy = function(sid, callback) { | ||
OrmStore.prototype.destroy = function(sid, callback) { | ||
callback = callback || noop; | ||
@@ -148,3 +148,3 @@ this.Session.one({sid: sid}, function(err, session) { | ||
Store.prototype.length = function(callback) { | ||
OrmStore.prototype.length = function(callback) { | ||
this.Session.count(callback); | ||
@@ -160,7 +160,7 @@ }; | ||
Store.prototype.clear = function(callback) { | ||
OrmStore.prototype.clear = function(callback) { | ||
this.Session.all().remove(callback); | ||
}; | ||
return Store; | ||
return OrmStore; | ||
}; |
{ | ||
"name": "connect-orm", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "orm session store for Connect", | ||
"keywords": ["connect", "session", "express"], | ||
"keywords": ["connect", "session", "express", "orm"], | ||
"main": "index.js", | ||
@@ -7,0 +7,0 @@ "scripts": { |
@@ -11,3 +11,4 @@ connect-orm | ||
var orm = require('orm'); | ||
var Store = require('connect-orm'); | ||
var session = require('express-session'); | ||
var OrmStore = require('connect-orm')(session); | ||
@@ -17,4 +18,4 @@ // connect to orm db somewhere in the app | ||
app.use(express.session({ | ||
store: new Store(db, { | ||
app.use(session({ | ||
store: new OrmStore(db, { | ||
table: 'sessions', // collection name | ||
@@ -28,3 +29,3 @@ maxAge: 1000 * 60 * 60 * 24 * 14 // default duration in milliseconds | ||
Note that maxAge can also be set in session.cookie.maxAge, see | ||
http://www.senchalabs.org/connect/session.html | ||
https://github.com/expressjs/session | ||
@@ -35,2 +36,6 @@ Features | ||
Automatic cleanup of expired sessions | ||
Compatible with express 3 (version 0.1): | ||
``` | ||
var OrmStore = require('connect-orm')(express); | ||
``` | ||
5893
38