瀏覽代碼

GOT RID OF DB

Nik Atlas 6 年之前
父節點
當前提交
839ff0583b

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 node_modules/
+database/mafaldadb/

+ 34 - 31
database/db.js

@@ -2,18 +2,19 @@ const level  = require('level');
 const sub    = require('level-sublevel');
 const search = require('level-search');
 
-const database = {
-	init: function(){
-		this.db = sub(level("./mydb", {valueEncoding: 'json'}));
+class Database {
+	constructor(){
+		console.log("Constructing database!")
+		this.db = sub(level("./database/mafaldadb", {valueEncoding: 'json'}));
 		this.index = search(this.db, 'search');
-	},
-	open: function(callback){
+	}
+	open(callback){
 		return this.db.open(callback);
-	},
-	close: function(callback){
+	}
+	close(callback){
 		return this.db.close(callback);
-	},
-	put: function(key, value){		
+	}
+	put(key, value){		
 		return  new Promise( (res,rej) => {
 			this.db.put(key, value, (err,values) => {
 				if(err)
@@ -21,8 +22,8 @@ const database = {
 				return res(values);
 			});
 		});
-	},
-	get: function(key){
+	}
+	get(key){
 		return  new Promise( (res,rej) => {
 			this.db.get(key, (err,values) => {
 				if(err)
@@ -30,32 +31,34 @@ const database = {
 				return res(values);
 			});
 		});
-	},
-	del: function(key, options, callback){
+	}
+	del(key, options, callback){
 		return this.db.del(key, options, callback);
-	},
-	batch: function(array, options, callback){
+	}
+	batch(array, options, callback){
 		return this.db.batch(array, options, callback);
-	},
-	isOpen: function(){
+	}
+	isOpen(){
 		return this.db.isOpen();
-	},
-	isClosed: function(){
+	}
+	isClosed(){
 		return this.db.isClosed();
-	},
-	createReadStream: function(options){
+	}
+	createReadStream(options){
 		return this.db.createReadStream(options);
-	},
-	createKeyStream: function(options){
+	}
+	createKeyStream(options){
 		return this.db.createKeyStream(options);
-	},
-	createValueStream: function(options){
+	}
+	createValueStream(options){
 		return this.db.createValueStream(options);
-	},
-	createSearchStream: function(keys, options){
+	}
+	createSearchStream(keys, options){
 		return this.index.createSearchStream(keys, options);	
-	},
-	search: this.createSearchStream
+	}
 };
-
-module.exports = database;
+let database = null; 
+function getSingleton() { 
+	return database = (database === null ? new Database() : database);
+}
+module.exports = getSingleton();

+ 0 - 2
database/index.js

@@ -2,8 +2,6 @@ const db = require('./db.js');
 const UserRepo = require('./repositories/users');
 
 
-db.init();
-
 let Repositories = {
 	Users: UserRepo
 };

二進制
database/mydb/000042.ldb


二進制
database/mydb/000044.ldb


二進制
database/mydb/000047.ldb


二進制
database/mydb/000048.log


+ 0 - 1
database/mydb/CURRENT

@@ -1 +0,0 @@
-MANIFEST-000046

+ 0 - 0
database/mydb/LOCK


+ 0 - 5
database/mydb/LOG

@@ -1,5 +0,0 @@
-2018/01/28-14:38:37.296 1188 Recovering log #45
-2018/01/28-14:38:37.297 1188 Level-0 table #47: started
-2018/01/28-14:38:37.302 1188 Level-0 table #47: 405 bytes OK
-2018/01/28-14:38:37.308 1188 Delete type=0 #45
-2018/01/28-14:38:37.309 1188 Delete type=3 #43

+ 0 - 5
database/mydb/LOG.old

@@ -1,5 +0,0 @@
-2018/01/28-14:37:34.470 2ae4 Recovering log #41
-2018/01/28-14:37:34.470 2ae4 Level-0 table #44: started
-2018/01/28-14:37:34.481 2ae4 Level-0 table #44: 406 bytes OK
-2018/01/28-14:37:34.488 2ae4 Delete type=0 #41
-2018/01/28-14:37:34.488 2ae4 Delete type=3 #39

二進制
database/mydb/MANIFEST-000046


二進制
database/repositories/mydb/000026.ldb


二進制
database/repositories/mydb/000028.ldb


二進制
database/repositories/mydb/000031.ldb


二進制
database/repositories/mydb/000034.ldb


二進制
database/repositories/mydb/000035.log


+ 0 - 1
database/repositories/mydb/CURRENT

@@ -1 +0,0 @@
-MANIFEST-000033

+ 0 - 0
database/repositories/mydb/LOCK


+ 0 - 5
database/repositories/mydb/LOG

@@ -1,5 +0,0 @@
-2018/01/28-15:00:48.261 1464 Recovering log #32
-2018/01/28-15:00:48.261 1464 Level-0 table #34: started
-2018/01/28-15:00:48.266 1464 Level-0 table #34: 898 bytes OK
-2018/01/28-15:00:48.272 1464 Delete type=0 #32
-2018/01/28-15:00:48.273 1464 Delete type=3 #30

+ 0 - 5
database/repositories/mydb/LOG.old

@@ -1,5 +0,0 @@
-2018/01/28-15:00:02.843 2970 Recovering log #29
-2018/01/28-15:00:02.843 2970 Level-0 table #31: started
-2018/01/28-15:00:02.848 2970 Level-0 table #31: 909 bytes OK
-2018/01/28-15:00:02.853 2970 Delete type=0 #29
-2018/01/28-15:00:02.854 2970 Delete type=3 #27

二進制
database/repositories/mydb/MANIFEST-000033