Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
EventsDown.prototype.batch = EventsDown.prototype._batch = function(operations, opts, cb) {
if (arguments.length === 0) return new abstract.AbstractChainedBatch(this)
if (typeof opts === 'function') return this.batch(operations, null, opts)
if (!opts) opts = {}
var events = this._events
this._down.batch(operations, opts, cb && function(err, value) {
if (err) return cb(err)
for (var i = 0; i < operations.length; i++) {
var o = operations[i]
if (o.type === 'del') events.emit('delete', o.key)
if (o.type === 'put') events.emit('write', o.key, notNumber(o.value))
}
cb(err, value)
})
}
const util = require('util')
const AbstractChainedBatch = require('abstract-leveldown').AbstractChainedBatch
const binding = require('./binding')
function ChainedBatch (db) {
AbstractChainedBatch.call(this, db)
this.context = binding.batch_init(db.context)
}
ChainedBatch.prototype._put = function (key, value) {
binding.batch_put(this.context, key, value)
}
ChainedBatch.prototype._del = function (key) {
binding.batch_del(this.context, key)
}
ChainedBatch.prototype._clear = function () {
SubDown.prototype._batch = function (operations, opts, cb) {
if (arguments.length === 0) return new abstract.AbstractChainedBatch(this)
if (!Array.isArray(operations)) return this.leveldown.batch.apply(null, arguments)
var subops = new Array(operations.length)
for (var i = 0; i < operations.length; i++) {
var o = operations[i]
subops[i] = {type: o.type, key: concat(this.prefix, o.key), value: o.value}
}
this.leveldown.batch(subops, opts, cb)
}
'use strict'
var AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
var AbstractChainedBatch = require('abstract-leveldown').AbstractChainedBatch
var AbstractIterator = require('abstract-leveldown').AbstractIterator
var inherits = require('inherits')
var Codec = require('level-codec')
var EncodingError = require('level-errors').EncodingError
var rangeMethods = ['approximateSize', 'compactRange']
module.exports = DB.default = DB
function DB (db, opts) {
if (!(this instanceof DB)) return new DB(db, opts)
var manifest = db.supports || {}
var additionalMethods = manifest.additionalMethods || {}
AbstractLevelDOWN.call(this, manifest)
TxDown.prototype._batch = function (operations, options, cb) {
if (arguments.length === 0) {
return new abs.AbstractChainedBatch(this)
}
if (!Array.isArray(operations)) {
return this.db.batch.apply(null, arguments)
}
var self = this
var tree = this._store
operations.forEach(function (o) {
var key = concat(self._getPrefix(o), o.key)
var isKeyBuf = Buffer.isBuffer(o.key)
if (o.type === 'put') {
var isValBuf = Buffer.isBuffer(o.value)
var value = o.value
if (value === null || value === undefined) {
value = isValBuf ? Buffer(0) : ''
}
if (!isValBuf && typeof value !== 'string') value = String(value)
HookDown.prototype._batch = function (operations, opts, cb) {
if (arguments.length === 0) return new abstract.AbstractChainedBatch(this)
var self = this
var preWork = this.prehooks.map(function (hook) {
return hook.bind(hook, { type: 'batch', array: operations, opts: opts })
})
this._runner(preWork, preCb)
function preCb (err) {
if (err) return cb(err)
if (!Array.isArray(operations)) return this.leveldown.batch.apply(null, operations, opts, postCb)
self.leveldown.batch(operations, opts, postCb)
}
function postCb (err) {
if (err) return cb(err)