Budibase is an open-source low-code platform for creating internal apps in minutes. Supports PostgreSQL, MySQL, MSSQL, MongoDB, Rest API, Docker, K8s 🚀
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.
 
 
 
 
 
 

53 lines
1.2 KiB

'use strict';
var inherits = require('inherits');
var Readable = require('readable-stream').Readable;
module.exports = ReadStream;
inherits(ReadStream, Readable);
function ReadStream(db, opts) {
if (!(this instanceof ReadStream)) {
return new ReadStream(db, opts);
}
Readable.call(this, {
objectMode: true
});
opts = opts || {};
var thisOpts = this.opts = {
since: 0
};
Object.keys(opts).forEach(function (key) {
thisOpts[key] = opts[key];
});
this.opts.returnDocs = false;
this.last = opts.since;
this.db = db;
this.changes = void 0;
this.canceled = false;
}
ReadStream.prototype._read = function () {
if (this.changes) {
return;
}
var self = this;
this.opts.since = this.last;
this.changes = this.db.changes(this.opts).on('complete', function (resp) {
self.cancel = function () {};
if (!resp.canceled) {
self.push(null);
}
});
this.changes.on('change', function (change) {
self.last = change.seq;
var more = self.push(change);
if (!more) {
self.changes.cancel();
}
});
};
ReadStream.prototype.cancel = function () {
this.canceled = true;
if (this.changes && typeof this.changes.cancel === 'function') {
return this.changes.cancel();
}
};