diff --git a/index.js b/index.js new file mode 100644 index 0000000..a30158b --- /dev/null +++ b/index.js @@ -0,0 +1,23 @@ +export default function (session, db) { + function NedbStore(options, callback=()=>{}) { + this.db = db; + this.db.loadDatabase(callback); + } + NedbStore.prototype.__proto__ = session.Store.prototype; + NedbStore.prototype.get = function (sid, callback) { + this.db.findOne({ sid: sid }, function (err, sess) { + return callback(err, sess ? sess.data : null ) + }); + }; + NedbStore.prototype.set = function (sid, data, callback) { + this.db.update({ sid: sid }, { sid: sid, data: data }, { multi: false, upsert: true }, function (err) { + return callback(err); + }); + }; + NedbStore.prototype.destroy = function (sid, callback) { + this.db.remove({ sid: sid }, { multi: false }, function (err) { + return callback(err); + }); + }; + return new NedbStore(); +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..5e8d874 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "express-session-nedb", + "version": "1.0.0", + "description": "使用 nedb 作为 session 的存储容器", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/InvisibleFuture/express-session-nedb.git" + }, + "author": "satori.love", + "license": "MIT", + "bugs": { + "url": "https://github.com/InvisibleFuture/express-session-nedb/issues" + }, + "homepage": "https://github.com/InvisibleFuture/express-session-nedb#readme" +}