Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: init db in overridable method for easier extending (#21)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
achingbrain committed Jun 27, 2019
1 parent 7dc7876 commit b21428c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b21428c

Please sign in to comment.