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

Commit

Permalink
🔥 remove approximateSize(), destroy(), repair() and getProperty()
Browse files Browse the repository at this point in the history
Lars-Magnus Skog committed Jul 27, 2017

Verified

This commit was signed with the committer’s verified signature. The key has expired.
mmarchini mary marchini
1 parent 0159c91 commit 0b3792a
Showing 5 changed files with 0 additions and 313 deletions.
79 changes: 0 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -120,13 +120,6 @@ db.put('name', 'LevelUP', function (err) {
* <a href="#createKeyStream"><code>db.<b>createKeyStream()</b></code></a>
* <a href="#createValueStream"><code>db.<b>createValueStream()</b></code></a>

### Special operations exposed by LevelDOWN

* <a href="#approximateSize"><code>db.db.<b>approximateSize()</b></code></a>
* <a href="#getProperty"><code>db.db.<b>getProperty()</b></code></a>
* <a href="#destroy"><code><b>leveldown.destroy()</b></code></a>
* <a href="#repair"><code><b>leveldown.repair()</b></code></a>

### Special Notes
* <a href="#writeStreams">What happened to <code><b>db.createWriteStream()</b></code></a>

@@ -475,78 +468,6 @@ The main driver for this was performance. While `db.createReadStream()` performs

Check out the implementations that the community has already produced [here](https://github.com/level/levelup/wiki/Modules#write-streams).

--------------------------------------------------------
<a name='approximateSize'></a>
### db.db.approximateSize(start, end, callback)
<code>approximateSize()</code> can used to get the approximate number of bytes of file system space used by the range `[start..end)`. The result may not include recently written data.

```js
var db = require('level')('./huge.db')

db.db.approximateSize('a', 'c', function (err, size) {
if (err) return console.error('Ooops!', err)
console.log('Approximate size of range is %d', size)
})
```

**Note:** `approximateSize()` is available via [LevelDOWN](https://github.com/level/leveldown/), which by default is accessible as the `db` property of your LevelUP instance. This is a specific LevelDB operation and is not likely to be available where you replace LevelDOWN with an alternative back-end via the `'db'` option.


--------------------------------------------------------
<a name='getProperty'></a>
### db.db.getProperty(property)
<code>getProperty</code> can be used to get internal details from LevelDB. When issued with a valid property string, a readable string will be returned (this method is synchronous).

Currently, the only valid properties are:

* <b><code>'leveldb.num-files-at-levelN'</code></b>: returns the number of files at level *N*, where N is an integer representing a valid level (e.g. "0").

* <b><code>'leveldb.stats'</code></b>: returns a multi-line string describing statistics about LevelDB's internal operation.

* <b><code>'leveldb.sstables'</code></b>: returns a multi-line string describing all of the *sstables* that make up contents of the current database.


```js
var db = require('level')('./huge.db')
console.log(db.db.getProperty('leveldb.num-files-at-level3'))
// → '243'
```

**Note:** `getProperty()` is available via [LevelDOWN](https://github.com/level/leveldown/), which by default is accessible as the `db` property of your LevelUP instance. This is a specific LevelDB operation and is not likely to be available where you replace LevelDOWN with an alternative back-end via the `'db'` option.


--------------------------------------------------------
<a name="destroy"></a>
### leveldown.destroy(location, callback)
<code>destroy()</code> is used to completely remove an existing LevelDB database directory. You can use this function in place of a full directory *rm* if you want to be sure to only remove LevelDB-related files. If the directory only contains LevelDB files, the directory itself will be removed as well. If there are additional, non-LevelDB files in the directory, those files, and the directory, will be left alone.

The callback will be called when the destroy operation is complete, with a possible `error` argument.

**Note:** `destroy()` is available via [LevelDOWN](https://github.com/level/leveldown/) which you will have to install seperately, e.g.:

```js
require('leveldown').destroy('./huge.db', function (err) { console.log('done!') })
```

--------------------------------------------------------
<a name="repair"></a>
### leveldown.repair(location, callback)
<code>repair()</code> can be used to attempt a restoration of a damaged LevelDB store. From the LevelDB documentation:

> If a DB cannot be opened, you may attempt to call this method to resurrect as much of the contents of the database as possible. Some data may be lost, so be careful when calling this function on a database that contains important information.
You will find information on the *repair* operation in the *LOG* file inside the store directory.

A `repair()` can also be used to perform a compaction of the LevelDB log into table files.

The callback will be called when the repair operation is complete, with a possible `error` argument.

**Note:** `repair()` is available via [LevelDOWN](https://github.com/level/leveldown/) which you will have to install seperately, e.g.:

```js
require('leveldown').repair('./huge.db', function (err) { console.log('done!') })
```

--------------------------------------------------------

<a name="events"></a>
41 changes: 0 additions & 41 deletions lib/levelup.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@

var EventEmitter = require('events').EventEmitter
var inherits = require('util').inherits
var deprecate = require('util').deprecate
var extend = require('xtend')
var prr = require('prr')
var DeferredLevelDOWN = require('deferred-leveldown')
@@ -287,32 +286,6 @@ LevelUP.prototype.batch = function (arr_, options, callback) {
})
}

LevelUP.prototype.approximateSize = deprecate(function (start_, end_, options, callback) {
var self = this
var start
var end

callback = getCallback(options, callback)

options = getOptions(options)

if (start_ === null || start_ === undefined || end_ === null ||
end_ === undefined || typeof callback !== 'function') {
return readError(this, 'approximateSize() requires start, end and callback arguments', callback)
}

start = this._codec.encodeKey(start_, options)
end = this._codec.encodeKey(end_, options)

this.db.approximateSize(start, end, function (err, size) {
if (err) {
return dispatchError(self, new OpenError(err), callback)
} else if (callback) {
callback(null, size)
}
})
}, 'db.approximateSize() is deprecated. Use db.db.approximateSize() instead')

LevelUP.prototype.readStream =
LevelUP.prototype.createReadStream = function (options) {
options = extend({keys: true, values: true}, this.options, options)
@@ -345,19 +318,5 @@ LevelUP.prototype.toString = function () {
return 'LevelUP'
}

function utilStatic (name) {
return function (location, callback) {
getLevelDOWN()[name](location, callback || function () {})
}
}

module.exports = LevelUP
module.exports.errors = require('level-errors')
module.exports.destroy = deprecate(
utilStatic('destroy'),
'levelup.destroy() is deprecated. Use leveldown.destroy() instead'
)
module.exports.repair = deprecate(
utilStatic('repair'),
'levelup.repair() is deprecated. Use leveldown.repair() instead'
)
84 changes: 0 additions & 84 deletions test/approximate-size-test.js

This file was deleted.

30 changes: 0 additions & 30 deletions test/argument-checking-test.js
Original file line number Diff line number Diff line change
@@ -59,36 +59,6 @@ buster.testCase('Argument checking', {
})
},

'test approximateSize() throwables': function (done) {
this.openTestDatabase(function (db) {
assert.exception(
db.approximateSize.bind(db),
{ name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' },
'no-arg approximateSize() throws'
)

assert.exception(
db.approximateSize.bind(db, 'foo'),
{ name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' },
'callback-less, 1-arg approximateSize() throws'
)

assert.exception(
db.approximateSize.bind(db, 'foo', 'bar'),
{ name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' },
'callback-less, 2-arg approximateSize() throws'
)

assert.exception(
db.approximateSize.bind(db, 'foo', 'bar', {}),
{ name: 'ReadError', message: 'approximateSize() requires start, end and callback arguments' },
'callback-less, 3-arg approximateSize(), no cb throws'
)

done()
})
},

'test batch() throwables': function (done) {
this.openTestDatabase(function (db) {
assert.exception(
79 changes: 0 additions & 79 deletions test/destroy-repair-test.js

This file was deleted.

0 comments on commit 0b3792a

Please sign in to comment.