|
@@ -5,7 +5,7 @@ const search = require('level-search');
|
|
const database = {
|
|
const database = {
|
|
init: function(){
|
|
init: function(){
|
|
this.db = sub(level("./mydb", {valueEncoding: 'json'}));
|
|
this.db = sub(level("./mydb", {valueEncoding: 'json'}));
|
|
- this.index = search(db, 'search');
|
|
|
|
|
|
+ this.index = search(this.db, 'search');
|
|
},
|
|
},
|
|
open: function(callback){
|
|
open: function(callback){
|
|
return this.db.open(callback);
|
|
return this.db.open(callback);
|
|
@@ -13,11 +13,23 @@ const database = {
|
|
close: function(callback){
|
|
close: function(callback){
|
|
return this.db.close(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){
|
|
del: function(key, options, callback){
|
|
return this.db.del(key, options, callback);
|
|
return this.db.del(key, options, callback);
|
|
@@ -39,6 +51,9 @@ const database = {
|
|
},
|
|
},
|
|
createValueStream: function(options){
|
|
createValueStream: function(options){
|
|
return this.db.createValueStream(options);
|
|
return this.db.createValueStream(options);
|
|
|
|
+ },
|
|
|
|
+ createSearchStream: function(keys, options){
|
|
|
|
+ return this.index.createSearchStream(keys, options);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|