You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
958 B

  1. 'use strict'
  2. module.exports = function (siOptions) {
  3. var siUtil = {}
  4. siUtil.countDocs = function (callback) {
  5. var count = 0
  6. const gte = 'DOCUMENT' + siOptions.keySeparator
  7. const lte = 'DOCUMENT' + siOptions.keySeparator + siOptions.keySeparator
  8. siOptions.indexes.createReadStream({gte: gte, lte: lte})
  9. .on('data', function (data) {
  10. count++
  11. })
  12. .on('error', function (err) {
  13. return callback(err, null)
  14. })
  15. .on('end', function () {
  16. return callback(null, count)
  17. })
  18. }
  19. siUtil.close = function (callback) {
  20. siOptions.indexes.close(function (err) {
  21. while (!siOptions.indexes.isClosed()) {
  22. // log not always working here- investigate
  23. if (siOptions.log) siOptions.log.info('closing...')
  24. }
  25. if (siOptions.indexes.isClosed()) {
  26. if (siOptions.log) siOptions.log.info('closed...')
  27. callback(err)
  28. }
  29. })
  30. }
  31. return siUtil
  32. }