summaryrefslogtreecommitdiff
path: root/bucky/search/bdb.js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-08 05:37:20 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-08 05:37:20 +0100
commit9978bb56fc2c56ad52930bde9bcaa561158a158a (patch)
tree0998cfc21091c6923b0bf3988a35ff82f1e58e98 /bucky/search/bdb.js
parentdd45551e4bf64ba472976b60986b9273449aae70 (diff)
searches working correctly
Diffstat (limited to 'bucky/search/bdb.js')
-rw-r--r--bucky/search/bdb.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/bucky/search/bdb.js b/bucky/search/bdb.js
new file mode 100644
index 0000000..ba0124d
--- /dev/null
+++ b/bucky/search/bdb.js
@@ -0,0 +1,38 @@
+var bdb_lib = require('berkeleydb')
+var dbenv = new bdb_lib.DbEnv();
+var bdb_status = dbenv.open('./search/db/env')
+console.log('openĀ /search/db:', bdb_status)
+
+var db
+
+function exitHandler(options, err) {
+ db.close()
+ // if (options.cleanup) console.log('clean');
+ if (err) console.log(err.stack);
+ if (options.exit) process.exit();
+}
+
+// do something when app is closing
+process.on('exit', exitHandler.bind(null, {cleanup: true}));
+
+// catches ctrl+c event
+process.on('SIGINT', exitHandler.bind(null, {exit: true}));
+
+// catches "kill pid" (for example: nodemon restart)
+process.on('SIGUSR1', exitHandler.bind(null, {exit: true}));
+process.on('SIGUSR2', exitHandler.bind(null, {exit: true}));
+
+//catches uncaught exceptions
+process.on('uncaughtException', exitHandler.bind(null, {exit:true}));
+
+function open(){
+ if (db) db.close()
+ var _db = new bdb_lib.Db(dbenv);
+ var bdb_status = _db.open('./search.db')
+ console.log('openĀ ./search.db:', bdb_status)
+ db = _db
+}
+
+open()
+
+module.exports = db