mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-23 16:56:08 +08:00
26 lines
613 B
JavaScript
26 lines
613 B
JavaScript
|
const Rx = require('rxjs/Rx');
|
||
|
const Sequelize = require('sequelize');
|
||
|
|
||
|
Sequelize.Model.prototype.streamAll = function streamAll(options = {}) {
|
||
|
return Rx.Observable.create((observer) => {
|
||
|
const chunkSize = options.chunkSize || 1000;
|
||
|
options.offset = 0;
|
||
|
options.limit = chunkSize;
|
||
|
|
||
|
const findFn = (opts) => {
|
||
|
this.findAll(opts).then((models = []) => {
|
||
|
observer.onNext(models)
|
||
|
if (models.length === chunkSize) {
|
||
|
opts.offset = chunkSize;
|
||
|
findFn(opts)
|
||
|
} else {
|
||
|
observer.onCompleted()
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
findFn(options)
|
||
|
})
|
||
|
}
|
||
|
|