From b21428c9d7f07818c3fd81283acc8abf3ef8f0fd Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 27 Jun 2019 12:41:05 +0200 Subject: [PATCH] fix: init db in overridable method for easier extending (#21) Sometimes you might want to pass a fully initialised level instance to the LevelDatastore constructor or use a singleton or something else. Instead of creating the level instance in the constructor this change adds a method that child classes can override to tweak the behaviour as they see fit. --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index c30ae2e..70a397f 100644 --- a/src/index.js +++ b/src/index.js @@ -17,7 +17,11 @@ class LevelDatastore { database = require('level') } - this.db = database(path, { + this.db = this._initDb(database, path, opts) + } + + _initDb (database, path, opts) { + return database(path, { ...opts, valueEncoding: 'binary', compression: false // same default as go