db.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const level = require('level');
  2. const sub = require('level-sublevel');
  3. const search = require('level-search');
  4. const database = {
  5. init: function(){
  6. this.db = sub(level("./mydb", {valueEncoding: 'json'}));
  7. this.index = search(db, 'search');
  8. },
  9. open: function(callback){
  10. return this.db.open(callback);
  11. },
  12. close: function(callback){
  13. return this.db.close(callback);
  14. },
  15. put: function(key, value, options, callback){
  16. return this.db.put(key, value, options, callback);
  17. },
  18. get: function(key, options, callback){
  19. return this.db.get(key, options, callback);
  20. },
  21. del: function(key, options, callback){
  22. return this.db.del(key, options, callback);
  23. },
  24. batch: function(array, options, callback){
  25. return this.db.batch(array, options, callback);
  26. },
  27. isOpen: function(){
  28. return this.db.isOpen();
  29. },
  30. isClosed: function(){
  31. return this.db.isClosed();
  32. },
  33. createReadStream: function(options){
  34. return this.db.createReadStream(options);
  35. },
  36. createKeyStream: function(options){
  37. return this.db.createKeyStream(options);
  38. },
  39. createValueStream: function(options){
  40. return this.db.createValueStream(options);
  41. }
  42. };
  43. module.exports = database;