Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow empty prefix option #184

Merged
merged 2 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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