Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

forgotten check-ins. doh

  • Loading branch information...
commit 1e21754441d3843d403643746f99fc6008b56efd 1 parent d88f716
Don Park donpark authored
Showing with 32 additions and 39 deletions.
  1. +31 −38 index.js
  2. +1 −1  package.json
69 index.js
View
@@ -1,15 +1,12 @@
(function() {
- var Schema, Session, SessionSchema, SessionStore, defaultCallback, mongoose;
- var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
- for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
- function ctor() { this.constructor = child; }
- ctor.prototype = parent.prototype;
- child.prototype = new ctor;
- child.__super__ = parent.prototype;
- return child;
- };
+ var Schema, Session, SessionSchema, SessionStore, defaultCallback, mongoose,
+ __hasProp = Object.prototype.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+
mongoose = require('mongeese').create();
+
Schema = mongoose.Schema;
+
SessionSchema = new Schema({
sid: {
type: String,
@@ -25,19 +22,17 @@
index: true
}
});
+
Session = mongoose.model('Session', SessionSchema);
+
defaultCallback = function(err) {};
- SessionStore = (function() {
- __extends(SessionStore, require('connect').session.Store);
+
+ SessionStore = (function(_super) {
+
+ __extends(SessionStore, _super);
+
function SessionStore(options) {
- var _ref;
- if (options != null) {
- if ((_ref = options.interval) != null) {
- _ref;
- } else {
- options.interval = 60000;
- };
- }
+ if (options != null) if (options.interval == null) options.interval = 60000;
mongoose.connect(options.url);
setInterval((function() {
return Session.remove({
@@ -47,10 +42,9 @@
}, defaultCallback);
}), options.interval);
}
+
SessionStore.prototype.get = function(sid, cb) {
- if (cb == null) {
- cb = defaultCallback;
- }
+ if (cb == null) cb = defaultCallback;
return Session.findOne({
sid: sid
}, function(err, session) {
@@ -65,11 +59,10 @@
}
});
};
+
SessionStore.prototype.set = function(sid, data, cb) {
var _ref;
- if (cb == null) {
- cb = defaultCallback;
- }
+ if (cb == null) cb = defaultCallback;
try {
return Session.update({
sid: sid
@@ -84,18 +77,16 @@
return cb(err);
}
};
+
SessionStore.prototype.destroy = function(sid, cb) {
- if (cb == null) {
- cb = defaultCallback;
- }
+ if (cb == null) cb = defaultCallback;
return Session.remove({
sid: sid
}, cb);
};
+
SessionStore.prototype.all = function(cb) {
- if (cb == null) {
- cb = defaultCallback;
- }
+ if (cb == null) cb = defaultCallback;
return Session.find({
expires: {
'$gte': new Date()
@@ -117,19 +108,21 @@
}
});
};
+
SessionStore.prototype.clear = function(cb) {
- if (cb == null) {
- cb = defaultCallback;
- }
+ if (cb == null) cb = defaultCallback;
return Session.drop(cb);
};
+
SessionStore.prototype.length = function(cb) {
- if (cb == null) {
- cb = defaultCallback;
- }
+ if (cb == null) cb = defaultCallback;
return Session.count({}, cb);
};
+
return SessionStore;
- })();
+
+ })(require('connect').session.Store);
+
module.exports = SessionStore;
+
}).call(this);
2  package.json
View
@@ -2,7 +2,7 @@
"author": "Don Park <donpark@docuverse.com> (http://blog.docuverse.com)",
"name": "session-mongoose",
"description": "connect session store implementation using Mongoose",
- "version": "0.0.1",
+ "version": "0.0.2",
"main": "./index.js",
"repository": {
"type": "git",
Please sign in to comment.
Something went wrong with that request. Please try again.