Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
🔥 remove .errorIfExists
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphtheninja committed Jul 31, 2017
1 parent 0fdd5cd commit 7c16fe9
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 67 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ var db = levelup(memdown)

* `'createIfMissing'` *(boolean, default: `true`)*: If `true`, will initialise an empty database at the specified location if one doesn't already exist. If `false` and a database doesn't exist you will receive an error in your `open()` callback and your database won't open.

* `'errorIfExists'` *(boolean, default: `false`)*: If `true`, you will receive an error in your `open()` callback if the database exists at the specified location.

* `'compression'` *(boolean, default: `true`)*: If `true`, all *compressible* data will be run through the Snappy compression algorithm before being stored. Snappy is very fast and shouldn't gain much speed by disabling so leave this on unless you have good reason to turn it off.

* `'cacheSize'` *(number, default: `8 * 1024 * 1024`)*: The size (in bytes) of the in-memory [LRU](http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used) cache with frequently used uncompressed block contents.
Expand Down
1 change: 0 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

var defaultOptions = {
createIfMissing: true,
errorIfExists: false,
keyEncoding: 'utf8',
valueEncoding: 'utf8',
compression: true
Expand Down
2 changes: 1 addition & 1 deletion test/benchmarks/engines/levelup-nosnappy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var levelup = require('../../../')

var createDb = function (location, callback) {
levelup(location, { createIfMissing: true, errorIfExists: true, compression: false }, function (err, db) {
levelup(location, { createIfMissing: true, compression: false }, function (err, db) {
setTimeout(callback.bind(null, err, db), 50)
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/benchmarks/engines/levelup-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var levelup = require('levelup')

var createDb = function (location, callback) {
levelup(location, { createIfMissing: true, errorIfExists: true }, function (err, db) {
levelup(location, { createIfMissing: true }, function (err, db) {
setTimeout(callback.bind(null, err, db), 50)
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/benchmarks/engines/levelup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var levelup = require('../../../')

var createDb = function (location, callback) {
levelup(location, { createIfMissing: true, errorIfExists: true }, function (err, db) {
levelup(location, { createIfMissing: true }, function (err, db) {
setTimeout(callback.bind(null, err, db), 50)
})
}
Expand Down
4 changes: 2 additions & 2 deletions test/binary-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ buster.testCase('Binary API', {
},

'test put() and get() with binary value {valueEncoding:binary} on createDatabase()': function (done) {
this.openTestDatabase({ createIfMissing: true, errorIfExists: true, valueEncoding: 'binary' }, function (db) {
this.openTestDatabase({ createIfMissing: true, valueEncoding: 'binary' }, function (db) {
db.put('binarydata', this.testData, function (err) {
refute(err)
db.get('binarydata', function (err, value) {
Expand Down Expand Up @@ -81,7 +81,7 @@ buster.testCase('Binary API', {
},

'test put() and get() with binary value {keyEncoding:utf8,valueEncoding:binary} on createDatabase()': function (done) {
this.openTestDatabase({ createIfMissing: true, errorIfExists: true, keyEncoding: 'utf8', valueEncoding: 'binary' }, function (db) {
this.openTestDatabase({ createIfMissing: true, keyEncoding: 'utf8', valueEncoding: 'binary' }, function (db) {
db.put('binarydata', this.testData, function (err) {
refute(err)
db.get('binarydata', function (err, value) {
Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports.cleanup = function (callback) {
}

module.exports.openTestDatabase = function () {
var options = typeof arguments[0] === 'object' ? arguments[0] : { createIfMissing: true, errorIfExists: true }
var options = typeof arguments[0] === 'object' ? arguments[0] : { createIfMissing: true }
var callback = typeof arguments[0] === 'function' ? arguments[0] : arguments[1]
var location = typeof arguments[0] === 'string' ? arguments[0] : module.exports.nextLocation()

Expand Down
10 changes: 5 additions & 5 deletions test/deferred-open-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buster.testCase('Deferred open()', {
'put() and get() on pre-opened database': function (done) {
var location = common.nextLocation()
// 1) open database without callback, opens in worker thread
var db = levelup(location, { createIfMissing: true, errorIfExists: true, valueEncoding: 'utf8' })
var db = levelup(location, { createIfMissing: true, valueEncoding: 'utf8' })

this.closeableDatabases.push(db)
this.cleanupDirs.push(location)
Expand Down Expand Up @@ -55,7 +55,7 @@ buster.testCase('Deferred open()', {
'batch() on pre-opened database': function (done) {
var location = common.nextLocation()
// 1) open database without callback, opens in worker thread
var db = levelup(location, { createIfMissing: true, errorIfExists: true, valueEncoding: 'utf8' })
var db = levelup(location, { createIfMissing: true, valueEncoding: 'utf8' })

this.closeableDatabases.push(db)
this.cleanupDirs.push(location)
Expand Down Expand Up @@ -93,7 +93,7 @@ buster.testCase('Deferred open()', {
'chained batch() on pre-opened database': function (done) {
var location = common.nextLocation()
// 1) open database without callback, opens in worker thread
var db = levelup(location, { createIfMissing: true, errorIfExists: true, valueEncoding: 'utf8' })
var db = levelup(location, { createIfMissing: true, valueEncoding: 'utf8' })

this.closeableDatabases.push(db)
this.cleanupDirs.push(location)
Expand Down Expand Up @@ -138,7 +138,7 @@ buster.testCase('Deferred open()', {
refute(err)
db.close(function (err) {
refute(err, 'no error')
db = levelup(location, { createIfMissing: false, errorIfExists: false })
db = levelup(location, { createIfMissing: false })
var rs = db.createReadStream()
rs.on('data', this.dataSpy)
rs.on('end', this.endSpy)
Expand All @@ -152,7 +152,7 @@ buster.testCase('Deferred open()', {
'maxListeners warning': function (done) {
var location = common.nextLocation()
// 1) open database without callback, opens in worker thread
var db = levelup(location, { createIfMissing: true, errorIfExists: true, valueEncoding: 'utf8' })
var db = levelup(location, { createIfMissing: true, valueEncoding: 'utf8' })
var stderrMock = this.mock(console)

this.closeableDatabases.push(db)
Expand Down
8 changes: 4 additions & 4 deletions test/encoding-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ buster.testCase('Encoding', {
'tearDown': common.commonTearDown,

'test safe decode in get()': function (done) {
this.openTestDatabase({ createIfMissing: true, errorIfExists: true, valueEncoding: 'utf8' }, function (db) {
this.openTestDatabase({ createIfMissing: true, valueEncoding: 'utf8' }, function (db) {
db.put('foo', 'this {} is [] not : json', function (err) {
refute(err)
db.close(function (err) {
refute(err)
db = levelup(db.location, { createIfMissing: false, errorIfExists: false, valueEncoding: 'json' })
db = levelup(db.location, { createIfMissing: false, valueEncoding: 'json' })
db.get('foo', function (err, value) {
assert(err)
assert.equals('EncodingError', err.name)
Expand All @@ -34,7 +34,7 @@ buster.testCase('Encoding', {
},

'test safe decode in readStream()': function (done) {
this.openTestDatabase({ createIfMissing: true, errorIfExists: true, valueEncoding: 'utf8' }, function (db) {
this.openTestDatabase({ createIfMissing: true, valueEncoding: 'utf8' }, function (db) {
db.put('foo', 'this {} is [] not : json', function (err) {
refute(err)
db.close(function (err) {
Expand All @@ -43,7 +43,7 @@ buster.testCase('Encoding', {
var dataSpy = this.spy()
var errorSpy = this.spy()

db = levelup(db.location, { createIfMissing: false, errorIfExists: false, valueEncoding: 'json' })
db = levelup(db.location, { createIfMissing: false, valueEncoding: 'json' })
db.readStream()
.on('data', dataSpy)
.on('error', errorSpy)
Expand Down
45 changes: 4 additions & 41 deletions test/init-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ buster.testCase('Init & open()', {

'default options': function (done) {
var location = common.nextLocation()
levelup(location, { createIfMissing: true, errorIfExists: true }, function (err, db) {
levelup(location, { createIfMissing: true }, function (err, db) {
refute(err, 'no error')
assert.isTrue(db.isOpen())
this.closeableDatabases.push(db)
Expand All @@ -38,7 +38,6 @@ buster.testCase('Init & open()', {
refute(err)
assert.isObject(db)
assert.isTrue(db.options.createIfMissing)
assert.isFalse(db.options.errorIfExists)
assert.equals(db.options.keyEncoding, 'utf8')
assert.equals(db.options.valueEncoding, 'utf8')
assert.equals(db.location, location)
Expand All @@ -57,14 +56,13 @@ buster.testCase('Init & open()', {
var location = common.nextLocation()
levelup(
location,
{ createIfMissing: true, errorIfExists: true, valueEncoding: 'binary' }, function (err, db) {
{ createIfMissing: true, valueEncoding: 'binary' }, function (err, db) {
refute(err)

this.closeableDatabases.push(db)
this.cleanupDirs.push(location)
assert.isObject(db)
assert.isTrue(db.options.createIfMissing)
assert.isTrue(db.options.errorIfExists)
assert.equals(db.options.keyEncoding, 'utf8')
assert.equals(db.options.valueEncoding, 'binary')
assert.equals(db.location, location)
Expand All @@ -82,14 +80,13 @@ buster.testCase('Init & open()', {
var location = common.nextLocation()
levelup(
location,
{ createIfMissing: true, errorIfExists: true, keyEncoding: 'ascii', valueEncoding: 'json' }, function (err, db) {
{ createIfMissing: true, keyEncoding: 'ascii', valueEncoding: 'json' }, function (err, db) {
refute(err)

this.closeableDatabases.push(db)
this.cleanupDirs.push(location)
assert.isObject(db)
assert.isTrue(db.options.createIfMissing)
assert.isTrue(db.options.errorIfExists)
assert.equals(db.options.keyEncoding, 'ascii')
assert.equals(db.options.valueEncoding, 'json')
assert.equals(db.location, location)
Expand All @@ -105,13 +102,12 @@ buster.testCase('Init & open()', {

'without callback': function (done) {
var location = common.nextLocation()
var db = levelup(location, { createIfMissing: true, errorIfExists: true })
var db = levelup(location, { createIfMissing: true })

this.closeableDatabases.push(db)
this.cleanupDirs.push(location)
assert.isObject(db)
assert.isTrue(db.options.createIfMissing)
assert.isTrue(db.options.errorIfExists)
assert.equals(db.location, location)

db.on('ready', function () {
Expand Down Expand Up @@ -145,39 +141,6 @@ buster.testCase('Init & open()', {
}.bind(this))
},

'open() with errorIfExists expects error if exists': function (done) {
levelup(this.cleanupDirs[0] = common.nextLocation(), { createIfMissing: true }, function (err, db) {
this.closeableDatabases.push(db)
refute(err) // sanity
levelup(this.cleanupDirs[0], { errorIfExists: true }, function (err) {
assert(err)
assert.isInstanceOf(err, Error)
assert.isInstanceOf(err, errors.LevelUPError)
assert.isInstanceOf(err, errors.OpenError)
done()
})
}.bind(this))
},

'open() with !errorIfExists does not expect error if exists': function (done) {
levelup(this.cleanupDirs[0] = common.nextLocation(), { createIfMissing: true }, function (err, db) {
refute(err) // sanity
this.closeableDatabases.push(db)
assert.isTrue(db.isOpen())

db.close(function () {
assert.isFalse(db.isOpen())

levelup(this.cleanupDirs[0], { errorIfExists: false }, function (err, db) {
refute(err)
this.closeableDatabases.push(db)
assert.isTrue(db.isOpen())
done()
}.bind(this))
}.bind(this))
}.bind(this))
},

'constructor with options argument uses factory': function (done) {
var db = levelup({ db: MemDOWN })
assert.isNull(db.location, 'location property is null')
Expand Down
1 change: 0 additions & 1 deletion test/inject-encoding-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ buster.testCase('JSON API', {
console.log(location)
levelup(location, {
createIfMissing: true,
errorIfExists: true,
valueEncoding: {
encode: msgpack.encode,
decode: msgpack.decode,
Expand Down
2 changes: 1 addition & 1 deletion test/json-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buster.testCase('JSON API', {
this.runTest = function (testData, assertType, done) {
var location = common.nextLocation()
this.cleanupDirs.push(location)
levelup(location, { createIfMissing: true, errorIfExists: true, valueEncoding: { encode: JSON.stringify, decode: JSON.parse } }, function (err, db) {
levelup(location, { createIfMissing: true, valueEncoding: { encode: JSON.stringify, decode: JSON.parse } }, function (err, db) {
refute(err)
if (err) return

Expand Down
2 changes: 1 addition & 1 deletion test/open-patchsafe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function test (fun) {
return function (done) {
var location = common.nextLocation()
// 1) open database without callback, opens in worker thread
var db = levelup(location, { createIfMissing: true, errorIfExists: true, valueEncoding: 'utf8' })
var db = levelup(location, { createIfMissing: true, valueEncoding: 'utf8' })

this.closeableDatabases.push(db)
this.cleanupDirs.push(location)
Expand Down
9 changes: 4 additions & 5 deletions test/read-stream-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ buster.testCase('ReadStream', {
},

'test hex encoding': function (done) {
var options = { createIfMissing: true, errorIfExists: true, keyEncoding: 'utf8', valueEncoding: 'hex' }
var options = { createIfMissing: true, keyEncoding: 'utf8', valueEncoding: 'hex' }
var data = [
{ type: 'put', key: 'ab', value: 'abcdef0123456789' }
]
Expand All @@ -386,7 +386,7 @@ buster.testCase('ReadStream', {
},

'test json encoding': function (done) {
var options = { createIfMissing: true, errorIfExists: true, keyEncoding: 'utf8', valueEncoding: 'json' }
var options = { createIfMissing: true, keyEncoding: 'utf8', valueEncoding: 'json' }
var data = [
{ type: 'put', key: 'aa', value: { a: 'complex', obj: 100 } },
{ type: 'put', key: 'ab', value: { b: 'foo', bar: [ 1, 2, 3 ] } },
Expand Down Expand Up @@ -414,7 +414,6 @@ buster.testCase('ReadStream', {
'test injectable encoding': function (done) {
var options = {
createIfMissing: true,
errorIfExists: true,
keyEncoding: 'utf8',
valueEncoding: {
decode: msgpack.decode,
Expand Down Expand Up @@ -529,7 +528,7 @@ buster.testCase('ReadStream', {
.on('close', delayed.delayed(callback, 0.05))
}
var open = function (reopen, location, callback) {
levelup(location, { createIfMissing: !reopen, errorIfExists: !reopen }, callback)
levelup(location, { createIfMissing: !reopen }, callback)
}
var write = function (db, callback) { db.batch(sourceData.slice(), callback) }
var close = function (db, callback) { db.close(callback) }
Expand Down Expand Up @@ -577,7 +576,7 @@ buster.testCase('ReadStream', {
refute(err)
db.close(function (err) {
refute(err)
var db2 = levelup(db.location, { createIfMissing: false, errorIfExists: false, valueEncoding: 'utf8' })
var db2 = levelup(db.location, { createIfMissing: false, valueEncoding: 'utf8' })
execute(db2)
})
})
Expand Down

0 comments on commit 7c16fe9

Please sign in to comment.