<commit_before>
var util              = require('util')
  , PassThrough       = require('stream').PassThrough

  , AbstractIterator  = require('abstract-leveldown').AbstractIterator
  , mysql             = require('mysql')

  , sqlHelper         = require('./sql')

  , MysqlIterator = function(db, options) {
      var self = this
        , query = []
        , start = options.start && options.start.length > 0 ? mysql.escape(options.start) : null
        , end = options.end && options.end.length > 0 ? mysql.escape(options.end) : null

      AbstractIterator.call(this, db)
      this._reverse = !!options.reverse
      this._keyAsBuffer = !!options.keyAsBuffer
      this._valueAsBuffer = !!options.valueAsBuffer

      this._stream  = new PassThrough({
          objectMode: true
      })

      this._stream.once('end', function() {
        self._endEmitted = true
      })

      query.push('SELECT * from ' + db.table)

      if (options.reverse) {
        if (start && end)
          query.push('WHERE `key` <= ' + start + ' AND `key` >= ' + end)
        else if (start)
          query.push('WHERE `key` <= ' + start)
        else if (end)
          query.push('WHERE `key` >= ' + end)
        query.push('ORDER BY `key` DESC')
      } else {
        if (start && end)
          query.push('WHERE `key` >= ' + start + ' AND `key` <= ' + end)
        else if (start)
          query.push('WHERE `key` >= ' + start)
        else if (end)
          query.push('WHERE `key` <= ' + end)
        query.push('ORDER BY `key` ASC')
      }

      if (options.limit)
        query.push('LIMIT ' + options.limit)

      db._streamingQuery(query.join('\n'), function(err, s) {
        self._foobar = s
        s.pipe(self._stream)
        s.once('close', function() {
          throw new Error('CLOSE')
        })
      })
    }

util.inherits(MysqlIterator, AbstractIterator)

MysqlIterator.prototype._next = function(callback) {
  var self = this
    , obj = this._stream.read()
    , onReadable = function() {
        self._stream.removeListener('end', onEnd)
        self._next(callback)
      }
    , onEnd = function() {
        self._stream.removeListener('readable', onReadable)
        callback()
      }
    , key
    , value<commit_msg>[fix] Support the levelup default that limit = -1 means no limit<commit_after>
var util              = require('util')
  , PassThrough       = require('stream').PassThrough

  , AbstractIterator  = require('abstract-leveldown').AbstractIterator
  , mysql             = require('mysql')

  , sqlHelper         = require('./sql')

  , MysqlIterator = function(db, options) {
      var self = this
        , query = []
        , start = options.start && options.start.length > 0 ? mysql.escape(options.start) : null
        , end = options.end && options.end.length > 0 ? mysql.escape(options.end) : null

      AbstractIterator.call(this, db)
      this._reverse = !!options.reverse
      this._keyAsBuffer = !!options.keyAsBuffer
      this._valueAsBuffer = !!options.valueAsBuffer

      this._stream  = new PassThrough({
          objectMode: true
      })

      this._stream.once('end', function() {
        self._endEmitted = true
      })

      query.push('SELECT * from ' + db.table)

      if (options.reverse) {
        if (start && end)
          query.push('WHERE `key` <= ' + start + ' AND `key` >= ' + end)
        else if (start)
          query.push('WHERE `key` <= ' + start)
        else if (end)
          query.push('WHERE `key` >= ' + end)
        query.push('ORDER BY `key` DESC')
      } else {
        if (start && end)
          query.push('WHERE `key` >= ' + start + ' AND `key` <= ' + end)
        else if (start)
          query.push('WHERE `key` >= ' + start)
        else if (end)
          query.push('WHERE `key` <= ' + end)
        query.push('ORDER BY `key` ASC')
      }

      if (options.limit && options.limit !== -1)
        query.push('LIMIT ' + options.limit)

      db._streamingQuery(query.join('\n'), function(err, s) {
        self._foobar = s
        s.pipe(self._stream)
        s.once('close', function() {
          throw new Error('CLOSE')
        })
      })
    }

util.inherits(MysqlIterator, AbstractIterator)

MysqlIterator.prototype._next = function(callback) {
  var self = this
    , obj = this._stream.read()
    , onReadable = function() {
        self._stream.removeListener('end', onEnd)
        self._next(callback)
      }
    , onEnd = function() {
        self._stream.removeListener('readable', onReadable)
        callback()
      }
    , key
    , value
{'fraction_non_alphanumeric': 0.14779943069848916, 'fraction_numerical': 0.0013137727173199037, 'mean_word_length': 2.059611520428667, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2591814', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1355, 'n_words': 291}