This commit is contained in:
satori 2021-11-17 05:28:02 +08:00
parent 62a55a4628
commit d3a23c9993
2 changed files with 42 additions and 0 deletions

23
index.js Normal file
View File

@ -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();
}

19
package.json Normal file
View File

@ -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"
}