import sqlite from "sqlite"; import { AbstractBatchEntityReaderStream, AbstractBatchEntityReaderStreamOptions } from "../../common/index"; import { BatchData, ReadCallback } from "batchjs"; /** * @interface * Options for the SqliteBatchEntityReader. * @extends AbstractBatchEntityReaderStreamOptions * @template T chunk entity * @template E row entity */ export interface SqliteBatchEntityReaderOptions extends AbstractBatchEntityReaderStreamOptions { dbConnectionFactory: () => Promise; query: string; rowToEntity: (row: E) => T; } /** * @class * Class that read data in batches of a specified size in SQLite databases. * @extends AbstractBatchEntityReaderStream * @template T chunk entity * @template E row entity */ export declare class SqliteBatchEntityReader extends AbstractBatchEntityReaderStream { private readonly dbConnectionFactory; private dbConnection; private readonly query; private readonly rowToEntity; private fetchEntityStatement; private entitiesRead; /** * @constructor * @param {SqliteBatchEntityReaderOptions} options - The options for the SqliteBatchEntityReader. * @param [options.dbConnectionFactory] {Function} - Function that creates a database connection. * @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: SqliteBatchEntityReaderOptions); /** * 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 finalizing the statement used to read entities and * 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 closing the active database connection * and setting the connection 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 closed. */ private disconnectDatabase; /** * Prepares a statement for fetching entities. If the statement has already been * prepared, it is reused. * @private * @param {sqlite.Database} db - The database connection. * @returns {Promise} The prepared statement. */ private prepareStatement; /** * Finalizes the statement used to fetch entities. This method should be * called when the reader is no longer needed to free up resources. * * @private */ private finalizeStatement; }