import { Pool } from "mysql2/promise"; import { AbstractBatchEntityReaderStream, AbstractBatchEntityReaderStreamOptions } from "../../common/index"; import { BatchData, ReadCallback } from "batchjs"; /** * @interface * Options for the MysqlBatchEntityReader. * @extends AbstractBatchEntityReaderStreamOptions * @template T chunk entity * @template E row entity */ export interface MysqlBatchEntityReaderOptions extends AbstractBatchEntityReaderStreamOptions { pool: Pool; query: string; rowToEntity: (row: E) => T; } /** * @class * Class that reads data in batches of a specified size from a MySQL database. * @extends AbstractBatchEntityReaderStream * @template T chunk entity * @template E row entity */ export declare class MysqlBatchEntityReader extends AbstractBatchEntityReaderStream { private readonly pool; private readonly query; private readonly rowToEntity; private client; private entitiesRead; /** * @constructor * @param {MysqlBatchEntityReaderOptions} options - The options for the MysqlBatchEntityReader. * @param [options.pool] {Pool} - The MySQL connection pool. * @param [options.query] {string} - SQL query to be executed (without LIMIT and OFFSET). * @param [options.rowToEntity] {Function} - Function that converts a row to an entity. */ constructor(options: MysqlBatchEntityReaderOptions); /** * Fetches a batch of data from the database. * * @private * @param {number} size - The size of the batch to fetch. * @returns {Promise>} A promise that resolves with the batch of data. */ protected fetch(size: number): Promise>; /** * Destroys the writer by closing the database connection. This method should be called when the * writer is no longer needed to free up resources. * @see AbstractBatchEntityReaderStream._destroy * @private * @param error {Error|null} - The error that caused the destruction. * @param callback {ReadCallback} - The callback function to be executed after destroying the reader. */ _destroy(error: Error | null, callback: ReadCallback): void; /** * Connects to the database by creating a new database connection if none * already exists, or by reusing an existing connection. * @private * @returns {Promise} A promise that resolves with the database connection. */ private connectDatabase; /** * Disconnects from the database by releasing the active database connection * and setting the client reference to null. This method should be called * when the reader is no longer needed to free up resources. * @returns {Promise} A promise that resolves when the database connection * is successfully released. */ private disconnectDatabase; }