Skip to content

Commit

Permalink
Restore support of empty prefix option
Browse files Browse the repository at this point in the history
This restores a previous behavior (of `level-js` < 3) that unknown to
us, was provided by the since-removed IDBWrapper.

Backport of #184.
  • Loading branch information
vweevers committed Nov 29, 2019
1 parent 556b0c6 commit 161bc16
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Level (location, opts) {
}

this.location = location
this.prefix = opts.prefix || DEFAULT_PREFIX
this.prefix = opts.prefix == null ? DEFAULT_PREFIX : opts.prefix
this.version = parseInt(opts.version || 1, 10)
}

Expand Down
21 changes: 21 additions & 0 deletions test/custom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ module.exports = function (leveljs, test, testCommon) {
})
})

test('empty prefix', function (t) {
var db = testCommon.factory({ prefix: '' })

t.ok(db.location, 'instance has location property')
t.is(db.prefix, '', 'instance has prefix property')

db.open(function (err) {
t.notOk(err, 'no open error')

var idb = db.db
var databaseName = idb.name
var storeNames = idb.objectStoreNames

t.is(databaseName, db.location, 'database name is prefixed')
t.is(storeNames.length, 1, 'created 1 object store')
t.is(storeNames.item(0), db.location, 'object store name equals location')

db.close(t.end.bind(t))
})
})

test('put Buffer value, get Buffer value', function (t) {
var level = testCommon.factory()
level.open(function (err) {
Expand Down
4 changes: 3 additions & 1 deletion test/structured-clone-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ var types = [

// Types that are not supported by the structured clone algorithm
var illegalTypes = [
{ name: 'Error', value: new Error() },
// Latest Chrome does seem to support Error, so skip this test.
// { name: 'Error', value: new Error() },

{ name: 'Function', value: function () {} },
{ name: 'DOMNode', value: global.document }
]
Expand Down

0 comments on commit 161bc16

Please sign in to comment.