bate
This commit is contained in:
		
							
								
								
									
										23
									
								
								index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								index.js
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										19
									
								
								package.json
									
									
									
									
									
										Normal 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"
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user