Skip to content

Commit

Permalink
[added] debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jergason committed Apr 1, 2015
1 parent e2e567c commit 59bcb02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var _ = require('lodash')
var debug = require('debug')('koa:generic-session-rethinkdb')

function RethinkSession(opts) {
this.connection = opts.connection
Expand Down Expand Up @@ -34,12 +35,15 @@ RethinkSession.prototype.table = function() {
}

RethinkSession.prototype.get = function* (sid) {
debug('get', sid)
var res = yield this.table().getAll(sid, {index: 'sid'})
debug('got', res[0])
return res[0]
}

RethinkSession.prototype.set = function* (sid, session) {
// check if there is a doc with that id
debug('set', sid, session)
var res = yield this.table().getAll(sid, {index: 'sid'})
if (res[0]) {
res = res[0]
Expand All @@ -57,8 +61,10 @@ RethinkSession.prototype.set = function* (sid, session) {
}

RethinkSession.prototype.destroy = function* (sid) {
debug('destroy', sid)
var res = yield this.table().getAll(sid, {index: 'sid'})
if (res[0]) {
debug('found session to destroy', res[0])
return yield this.table().get(res[0].id).delete()
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"rethinkdbdash": "1.16.13"
},
"dependencies": {
"debug": "2.1.3",
"lodash": "3.6.0"
}
}
}

0 comments on commit 59bcb02

Please sign in to comment.