level-version icon indicating copy to clipboard operation
level-version copied to clipboard

versionLimit, minVersion, maxVersion are filtered in-memory

Open timoxley opened this issue 10 years ago • 0 comments

This should probably be implemented as levelup's gte/lte/limit options instead.

    var filter = through({objectMode: true}, function (record, encoding, cb) {
      if (typeof record != "object") {
        if (options.keys) record = {key: record}
        if (options.values) record = {value: record}
        // if both are true... wtf?
      }

      // split off version key & add it to record
      var kv = unmakeKey(sep, record.key)

      if (options.versionLimit) {
        if (kv.key != this.currentKey) {
          this.currentKey = kv.key
          this.currentCount = 0
        }
        if (this.currentCount++ >= options.versionLimit) return cb()
      }

      if (kv.version >= options.minVersion && kv.version <= options.maxVersion) {
        record.version = kv.version
        record.key = kv.key
        this.push(record)
      }
      cb()
    })

https://github.com/brycebaril/level-version/blob/0941eb7cda460e50ddf9818c21712b0484f658e9/index.js#L186-L210

timoxley avatar Aug 17 '15 04:08 timoxley