import { FindOptions } from "sequelize"; import { Model as SequelizeModel } from "sequelize-typescript"; class Model extends SequelizeModel { /** * Find all models in batches, calling the callback function for each batch. * * @param query The query options. * @param callback The function to call for each batch of results */ static async findAllInBatches( query: FindOptions, callback: (results: Array, query: FindOptions) => Promise ) { if (!query.offset) { query.offset = 0; } if (!query.limit) { query.limit = 10; } let results; do { // @ts-expect-error this T results = await this.findAll(query); await callback(results, query); query.offset += query.limit; } while (results.length >= query.limit); } } export default Model;