Iterator
@constructor
@ignore
@param {LowlevelUp} db
@param {Object} options
354250
function Iterator(db, options) {
  options = new IteratorOptions(options);
  options.keyAsBuffer = db.options.bufferKeys;

  this.iter = db.db.iterator(options);
}
443173
function (dbname, callback) {
    var executeDB = load('db');
    this.internals.argv._.push(dbname);
    this.internals.mode = 'create';
    return Promise.fromCallback(
      function (callback) {
        executeDB(this.internals, this.config, callback);
      }.bind(this)
    ).asCallback(callback);
  }
1338497
function initDB () {
  return db.listDatabases()
    .then(response => {
      if (response.data.indexOf(dbName) !== -1) {
        // database already exists
        return Promise.resolve('ok')
      } else {
        // create new database
        return db.createDatabase(dbName).then(() => 'ok')
      }
    })
}
1189909
function constructor(models, options) {
      if (!Array.isArray(models)) {
        options = models;
        models = [];
      }

      options = options || {};

      //
      // Set the database name if it was provided in the options.
      //
      if (options.url) this.url = options.url;
      if (options.database) this.database = options.database;

      //
      // Define restricted non-enumerated properties.
      //
      predefine(this, fossa);

      //
      // Call original Backbone Model constructor.
      //
      backbone.Collection.call(this, models, options);
    }
65995
function each (array, iterator, cb) {
  var len = array.length
  array.forEach(function (item, i) {
    iterator.call(null, item, i, done)
  })
  function done () {
    if (!--len) {
      return cb && cb()
    }
  }
}
1031553
function iterate(iterator, callback) {
	        var self = this;

	        var promise = self.ready().then(function () {
	            var dbInfo = self._dbInfo;
	            var keyPrefix = dbInfo.keyPrefix;
	            var keyPrefixLength = keyPrefix.length;
	            var length = localStorage.length;

	            // We use a dedicated iterator instead of the `i` variable below
	            // so other keys we fetch in localStorage aren't counted in
	            // the `iterationNumber` argument passed to the `iterate()`
	            // callback.
	            //
	            // See: github.com/mozilla/localForage/pull/435#discussion_r38061530
	            var iterationNumber = 1;

	            for (var i = 0; i < length; i++) {
	                var key = localStorage.key(i);
	                if (key.indexOf(keyPrefix) !== 0) {
	                    continue;
	                }
	                var value = localStorage.getItem(key);

	                // If a result was found, parse it from the serialized
	                // string into a JS object. If result isn't truthy, the
	                // key is likely undefined and we'll pass it straight
	                // to the iterator.
	                if (value) {
	                    value = dbInfo.serializer.deserialize(value);
	                }

	                value = iterator(value, key.substring(keyPrefixLength), iterationNumber++);

	                if (value !== void 0) {
	                    return value;
	                }
	            }
	        });

	        executeCallback(promise, callback);
	        return promise;
	    }
67364
function runProgramLogic() {
  var entries = db.getCollection("entries");
  var entryCount = entries.count();
  var now = new Date();

  console.log("old number of entries in database : " + entryCount);

  entries.insert({ x: now.getTime(), y: 100 - entryCount });
  entryCount = entries.count();

  console.log("new number of entries in database : " + entryCount);
  console.log("");
  
  // manually save
  db.saveDatabase(function(err) {
    if (err) {
      console.log(err);
    }
    else {
      console.log("saved... it can now be loaded or reloaded with up to date data");
    }
  });
}
1125202
function queryDatabase(db, expr) {
  // TODO(benvanik): allow the user to switch zone.
  var zone = db.getZones()[0];

  // If the user provided an expression on the command line, use that.
  if (expr && expr.length) {
    issue(expr);
    return 0;
  }

  var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });
  rl.on('line', function(line) {
    line = line.trim();
    if (line == 'q' || line == 'quit') {
      rl.close();
      return;
    }

    issue(line);

    rl.prompt();
  });
  rl.on('close', function() {
    console.log('');
    db.dispose();
    process.exit(0);
  });
  rl.setPrompt('> ');
  rl.prompt();

  function issue(expr) {
    console.log('Expression: ' + expr);

    var result;
    try {
      result = zone.query(expr);
    } catch (e) {
      console.log(e);
      return;
    }

    var xexpr = result.getCompiledExpression();
    console.log(xexpr.toString());
    console.log('');

    var resultValue = result.getValue();
    if (resultValue instanceof wtf.db.EventIterator) {
      var it = resultValue;
      if (!it.getCount()) {
        console.log('Nothing matched');
      } else {
        console.log('Results: (' + it.getCount() + ' total)');
        for (; !it.done(); it.next()) {
          util.logEvent(it, zone);
        }
      }
    } else if (typeof resultValue == 'boolean' ||
        typeof resultValue == 'number' ||
        typeof resultValue == 'string') {
      console.log('Result:');
      logResult(resultValue);
    } else if (!resultValue) {
      // Note we test this after so that 0/strings/etc are handled.
      console.log('Nothing matched');
    } else if (resultValue.length) {
      console.log('Results: (' + resultValue.length + ' total)');
      for (var n = 0; n < resultValue.length; n++) {
        logResult(resultValue[n]);
      }
    } else {
      console.log('Result:');
      logResult(resultValue);
    }

    console.log('');
    console.log('Took ' + result.getDuration().toFixed(3) + 'ms');
  }
}
15201
function scanIndex(leveldb, options) {
  return new P(function(resolve, reject) {
    var datas = [];
    var resolved = false;
    function fin() {
      if (resolved) {
        return;
      }
      resolve(P.all(datas));
      resolved = true;
    }
    leveldb.createKeyStream(options)
      .on('data', function(key) {
        var i = key.lastIndexOf('\x00');
        var key = key.substr(i + 1);
        datas.push(leveldb.getAsync(key));
      })
      .on('close', fin)
      .on('end', fin)
      .on('error', function(err) {
        reject(err);
      })
  });
}
879714
function Iterator() {
    var items = Array.prototype.slice.call(arguments, 0);

    this.items = (items.length == 1 && Array.isArray(items[0])) ? items[0] : items;
    this.reset();
}
1222102
function initializeDB() {
  db = new loki('perftest');

  var start, end, totalTime;
  var totalTimes = [];
  var totalMS = 0.0;

  samplecoll = db.addCollection('samplecoll');

  for (var idx=0; idx < arraySize; idx++) {
    var v1 = genRandomVal();
    var v2 = genRandomVal();

    start = performance.now();
    samplecoll.insert({
      customId: idx,
      val: v1,
      val2: v2,
      val3: "more data 1234567890"
    });
    end = performance.now() - start;
    totalTimes.push([0, end * 1e6]);
  }

  for(idx=0; idx < totalTimes.length; idx++) {
    totalMS += totalTimes[idx][0] * 1e3 + totalTimes[idx][1]/1e6;
  }

  totalMS = totalMS.toFixed(2);
  var rate = arraySize * 1000 / totalMS;
  rate = rate.toFixed(2);
  trace("load (insert) : " + totalMS + "ms (" + rate + ") ops/s");
}
658784
function getDatabase(database, options, callback) {
    getDatabaseConnector(database, options, returnDatabase)

    function returnDatabase(err, databaseConnector) {
        if (err) {
            return callback(err)
        }

        var db = databaseConnector.db(database)

        callback(null, db)
    }
}
21680
function setupDbHelper( user_options ) {
  var options = user_options || {}

  /**
   * @returns {Promise<MongooseThenable>}
   */
  function setupDb() {
    return connection( options.connection )
      .then(
        /**
         * @param {Object} db
         * @param {Function} db.model
         *
         * @throws {Error}
         * @returns {*}
         */
        function ( db ) {
          try {
            if ( Array.isArray( options.schemas ) ) {
              options.schemas.forEach(
                function ( schema ) {
                  var keys = Object.keys( schema );

                  db.model( keys[ 0 ], schema[ keys[ 0 ] ] );
                }
              );
            }

            return db;
          } catch ( err ) {
            throw err;
          }
        }
      )
      .catch(
        function ( err ) {
          throw err
        }
      )
  }

  return setupDb
}
1177662
function iterator (db, opts) {
  if (!iterator.available(db)) {
    throw new Error('level-iterator: this database does not expose iterators')
  }

  // If db exposes iterators, assume they do the decoding
  if (typeof db.iterator === 'function') {
    return db.iterator(opts)
  }

  // If it's a levelup instance, use its codec and iterate the *DOWN db
  const codec = db._codec

  opts = codec.encodeLtgt({
    ...db.options,
    keys: true,
    values: true,
    limit: -1,
    ...( opts || {} )
  })

  opts.keyAsBuffer   = codec.keyAsBuffer(opts)
  opts.valueAsBuffer = codec.valueAsBuffer(opts)

  const iter = db.db.iterator(opts)
  const wrapper = { end: iter.end.bind(iter) }

  wrapper.next = function outerNext (cb) {
    iter.next(function innerNext (err, key, value) {
      if (err) cb(err)
      else if (key === undefined && value === undefined) cb()
      else {
        key = opts.keys ? codec.decodeKey(key, opts) : null
        value = opts.values ? codec.decodeValue(value, opts) : null

        cb(null, key, value)
      }
    })
  }

  if (typeof iter.seek === 'function') {
    wrapper.seek = function outerSeek (target) {
      iter.seek(codec.encodeKey(target, opts))
    }
  } else {
    wrapper.seek = seekNotSupported
  }

  return wrapper
}
236643
function iterate(iterator, callback) {
        var self = this;

        var promise = new Promise(function(resolve, reject) {
            self.ready().then(function() {
                var dbInfo = self._dbInfo;
                var store = dbInfo.db.transaction(dbInfo.storeName, 'readonly')
                                     .objectStore(dbInfo.storeName);

                var req = store.openCursor();

                req.onsuccess = function() {
                    var cursor = req.result;

                    if (cursor) {
                        var result = iterator(cursor.value, cursor.key);

                        if (result !== void(0)) {
                            resolve(result);
                        } else {
                            cursor["continue"]();
                        }
                    } else {
                        resolve();
                    }
                };

                req.onerror = function() {
                    reject(req.error);
                };
            })["catch"](reject);
        });

        executeDeferedCallback(promise, callback);

        return promise;
    }
147203
void closeIterator(LevelDBIterator<?> it) throws IOException {
    synchronized (this._db) {
      DB _db = this._db.get();
      if (_db != null) {
        it.close();
      }
    }
  }
790620
function(v, i) {
      if (v === undefined || v === null) return;
      failed += !iterator.call(context, v, type, level, i);
    }