How to use the abstract-leveldown.AbstractChainedBatch function in abstract-leveldown

To help you get started, we’ve selected a few abstract-leveldown examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mafintosh / level-events / eventsdown.js View on Github external
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)
  })
}
github Level / leveldown / chained-batch.js View on Github external
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 () {
github Level / subleveldown / leveldown.js View on Github external
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)
}
github Level / encoding-down / index.js View on Github external
'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)
github cshum / level-transactions / leveldown.js View on Github external
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)
github hypermodules / level-hookdown / leveldown.js View on Github external
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)