import { QueryRunner } from 'typeorm' ; export class MigrationHelpers { queryRunner : QueryRunner ; constructor ( queryRunner ) { this . queryRunner = queryRunner ; } async runChunked ( query , operation , limit = 100 ) { let offset = 0 ; let chunkedQuery ; let chunkedQueryResults ; do { chunkedQuery = this . chunkQuery ( query , limit , offset ) ; chunkedQueryResults = ( await this . queryRunner . query ( chunkedQuery ) ) as unknown [ ] ; await operation ( [ ... chunkedQueryResults ] ) ; offset += limit ; } while ( chunkedQueryResults . length === limit ) ; } private chunkQuery ( query , limit , offset = 0 ) { return `
			${ query }
			LIMIT ${ limit }
			OFFSET ${ offset }
		` ; } }