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

Commit e19ec96

Browse files
committed
deprecate .approximateSize()
1 parent 681c6ce commit e19ec96

3 files changed

Lines changed: 37 additions & 55 deletions

File tree

lib/levelup.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var EventEmitter = require('events').EventEmitter
88
, inherits = require('util').inherits
9+
, deprecate = require('util').deprecate
910
, extend = require('xtend')
1011
, prr = require('prr')
1112
, DeferredLevelDOWN = require('deferred-leveldown')
@@ -317,31 +318,30 @@ LevelUP.prototype.batch = function (arr_, options, callback) {
317318
})
318319
}
319320

320-
// DEPRECATED: prefer accessing LevelDOWN for this: db.db.approximateSize()
321-
LevelUP.prototype.approximateSize = function (start_, end_, options, callback) {
322-
var self = this
323-
, start
324-
, end
325-
326-
callback = getCallback(options, callback)
327-
328-
options = getOptions(options)
329-
330-
if (start_ === null || start_ === undefined
331-
|| end_ === null || end_ === undefined || 'function' !== typeof callback)
332-
return readError(this, 'approximateSize() requires start, end and callback arguments', callback)
333-
334-
start = this._codec.encodeKey(start_, options)
335-
end = this._codec.encodeKey(end_, options)
336-
337-
this.db.approximateSize(start, end, function (err, size) {
338-
if (err) {
339-
return dispatchError(self, new OpenError(err), callback)
340-
} else if (callback) {
341-
callback(null, size)
342-
}
343-
})
344-
}
321+
LevelUP.prototype.approximateSize = deprecate(function (start_, end_, options, callback) {
322+
var self = this
323+
, start
324+
, end
325+
326+
callback = getCallback(options, callback)
327+
328+
options = getOptions(options)
329+
330+
if (start_ === null || start_ === undefined
331+
|| end_ === null || end_ === undefined || 'function' !== typeof callback)
332+
return readError(this, 'approximateSize() requires start, end and callback arguments', callback)
333+
334+
start = this._codec.encodeKey(start_, options)
335+
end = this._codec.encodeKey(end_, options)
336+
337+
this.db.approximateSize(start, end, function (err, size) {
338+
if (err) {
339+
return dispatchError(self, new OpenError(err), callback)
340+
} else if (callback) {
341+
callback(null, size)
342+
}
343+
})
344+
}, 'db.approximateSize() is deprecated. Use db.db.approximateSize() instead')
345345

346346
LevelUP.prototype.readStream =
347347
LevelUP.prototype.createReadStream = function (options) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ buster.testCase('approximateSize()', {
1515
'setUp': common.commonSetUp
1616
, 'tearDown': common.commonTearDown
1717

18+
, 'approximateSize() is deprecated': function (done) {
19+
this.openTestDatabase(function (db) {
20+
var error = console.error
21+
console.error = function(str){
22+
console.error = error
23+
assert.equals(str, 'db.approximateSize() is deprecated. Use db.db.approximateSize() instead')
24+
done()
25+
}
26+
db.approximateSize('a', 'z', function(){})
27+
})
28+
}
29+
1830
, 'approximateSize() works on empty database': function (done) {
1931
this.openTestDatabase(function (db) {
2032
db.approximateSize('a', 'z', function(err, size) {

test/get-put-del-test.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -147,34 +147,4 @@ buster.testCase('get() / put() / del()', {
147147
})
148148
}
149149

150-
, 'test approximateSize() throwables': function (done) {
151-
this.openTestDatabase(function (db) {
152-
153-
assert.exception(
154-
db.approximateSize.bind(db)
155-
, { name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' }
156-
, 'no-arg approximateSize() throws'
157-
)
158-
159-
assert.exception(
160-
db.approximateSize.bind(db, 'foo')
161-
, { name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' }
162-
, 'callback-less, 1-arg approximateSize() throws'
163-
)
164-
165-
assert.exception(
166-
db.approximateSize.bind(db, 'foo', 'bar')
167-
, { name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' }
168-
, 'callback-less, 2-arg approximateSize() throws'
169-
)
170-
171-
assert.exception(
172-
db.approximateSize.bind(db, 'foo', 'bar', {})
173-
, { name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' }
174-
, 'callback-less, 3-arg approximateSize(), no cb throws'
175-
)
176-
177-
done()
178-
})
179-
}
180150
})

0 commit comments

Comments
 (0)