Dim Dim 6 роки тому
батько
коміт
64c8a7f6fe

+ 2 - 1
.gitignore

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

+ 21 - 6
database/db.js

@@ -5,7 +5,7 @@ const search = require('level-search');
 const database = {
 	init: function(){
 		this.db = sub(level("./mydb", {valueEncoding: 'json'}));
-		this.index = search(db, 'search');
+		this.index = search(this.db, 'search');
 	},
 	open: function(callback){
 		return this.db.open(callback);
@@ -13,11 +13,23 @@ const database = {
 	close: function(callback){
 		return this.db.close(callback);
 	},
-	put: function(key, value, options, callback){
-		return this.db.put(key, value, options, callback);
-	},
-	get: function(key, options, callback){
-		return this.db.get(key, options, callback);
+	put: function(key, value){		
+		return  new Promise( (res,rej) => {
+			this.db.put(key, value, (err,values) => {
+				if(err)
+					return rej(err);
+				return res(values);
+			});
+		});
+	},
+	get: function(key){
+		return  new Promise( (res,rej) => {
+			this.db.get(key, (err,values) => {
+				if(err)
+					return rej(err);
+				return res(values);
+			});
+		});
 	},
 	del: function(key, options, callback){
 		return this.db.del(key, options, callback);
@@ -39,6 +51,9 @@ const database = {
 	},
 	createValueStream: function(options){
 		return this.db.createValueStream(options);
+	},
+	createSearchStream: function(keys, options){
+		return this.index.createSearchStream(keys, options);	
 	}
 };
 

+ 12 - 3
database/db.test.js

@@ -12,6 +12,15 @@ database.init();
 //   })
 // })
 
-database.put('namezzzzzz', {asd: "gdfhdfh"}).then(function(value){
-	return database.get('namezzzzzz');
-}).then(console.log);
+database.put('asdad', {username: "nik"}).
+then(() => database.put('asdad2', {username: "nik2"})).
+then(() => database.put('asdad3', {username: "nik3"})).
+then(() => database.put('asdad4', {username: "nik4"})).
+then(() => database.put('asdad5', {username: "nik5"})).then(function(value){
+	return database.get('naaa');
+}).//then(console.log).
+then(() => {
+	database.index.search(['username', 'dimos'])//.on('data', (a) => console.log(a))
+	.then(console.log);
+})
+.catch(console.log);

BIN
database/mydb/000026.ldb


BIN
database/mydb/000030.ldb


BIN
database/mydb/000033.ldb


BIN
database/mydb/000036.ldb


BIN
database/mydb/000037.log


BIN
database/mydb/000038.ldb


+ 1 - 1
database/mydb/CURRENT

@@ -1 +1 @@
-MANIFEST-000035
+MANIFEST-000145

+ 9 - 6
database/mydb/LOG

@@ -1,6 +1,9 @@
-2018/01/20-19:13:30.720 1380 Recovering log #34
-2018/01/20-19:13:30.720 1380 Level-0 table #36: started
-2018/01/20-19:13:30.787 1380 Level-0 table #36: 201 bytes OK
-2018/01/20-19:13:30.877 1380 Delete type=0 #34
-2018/01/20-19:13:30.878 1380 Delete type=3 #32
-2018/01/20-19:13:30.879 b4 Compacting 4@0 + 0@1 files
+2018/01/20-20:45:03.080 334 Recovering log #144
+2018/01/20-20:45:03.080 334 Level-0 table #146: started
+2018/01/20-20:45:03.178 334 Level-0 table #146: 394 bytes OK
+2018/01/20-20:45:03.246 334 Delete type=0 #144
+2018/01/20-20:45:03.247 334 Delete type=2 #145
+2018/01/20-20:45:03.247 334 Delete type=3 #142
+2018/01/20-20:45:03.249 164 Compacting 8@0 + 1@1 files
+2018/01/20-20:45:03.299 164 Generated table #148@0: 18 keys, 603 bytes
+2018/01/20-20:45:03.299 164 Compacted 8@0 + 1@1 files => 603 bytes

+ 7 - 6
database/mydb/LOG.old

@@ -1,6 +1,7 @@
-2018/01/20-19:09:35.367 15d0 Recovering log #31
-2018/01/20-19:09:35.367 15d0 Level-0 table #33: started
-2018/01/20-19:09:35.440 15d0 Level-0 table #33: 201 bytes OK
-2018/01/20-19:09:35.553 15d0 Delete type=0 #31
-2018/01/20-19:09:35.554 15d0 Delete type=3 #29
-2018/01/20-19:09:35.606 11b0 Moved #23 to level-1 198 bytes OK: files[ 3 4 0 0 0 0 0 ]
+2018/01/20-20:44:34.468 3f8 Recovering log #141
+2018/01/20-20:44:34.469 3f8 Level-0 table #143: started
+2018/01/20-20:44:34.541 3f8 Level-0 table #143: 394 bytes OK
+2018/01/20-20:44:34.632 3f8 Delete type=0 #141
+2018/01/20-20:44:34.632 3f8 Delete type=2 #142
+2018/01/20-20:44:34.633 3f8 Delete type=3 #139
+2018/01/20-20:44:34.634 ab4 Compacting 7@0 + 1@1 files

BIN
database/mydb/MANIFEST-000035


+ 4 - 0
package.json

@@ -9,8 +9,12 @@
     "body-parser": "~1.18.2",
     "cookie-parser": "~1.4.3",
     "debug": "~2.6.9",
+    "encoding-down": "^3.0.1",
     "express": "~4.15.5",
     "level": "^2.1.1",
+    "level-search": "^1.8.0",
+    "level-sublevel": "^6.6.1",
+    "levelup": "^2.0.1",
     "morgan": "~1.9.0",
     "pug": "2.0.0-beta11",
     "serve-favicon": "~2.4.5"