import sqlite from "sqlite"; import { AbstractBatchEntityWriterStream, AbstractBatchEntityWriterStreamOptions } from "../../common/index"; import { BatchData, WriteCallback } from "batchjs"; /** * @interface * Options for the SqliteBatchEntityWriter. * @extends AbstractBatchEntityWriterStreamOptions * @template T chunk entity */ export interface SqliteBatchEntityWriterOptions extends AbstractBatchEntityWriterStreamOptions { dbConnectionFactory: () => Promise; prepareStatement: string; saveEntity: (entity: T, stmt: sqlite.Statement) => Promise; } /** * @class * Class that write data in batches of a specified size in SQLite databases. * @extends AbstractBatchEntityWriterStream * @template T chunk entity */ export declare class SqliteBatchEntityWriter extends AbstractBatchEntityWriterStream { private readonly dbConnectionFactory; private readonly prepareStatementString; private readonly saveEntity; private saveEntityStatement; /** * @constructor * @param {SqliteBatchEntityWriterOptions} options - The options for the SqliteBatchEntityWriter. * @param [options.dbConnectionFactory] {Function} - Function that creates a database connection. * @param [options.prepareStatementString] {string} - Insert SQL prepared statement to be executed. * @param [options.saveEntity] {Function} - Function that saves an entity in the database. */ constructor(options: SqliteBatchEntityWriterOptions); /** * Writes a batch of data to the storage. * * @protected * @param {BatchData} chunk - The batch of data to write to the storage. * @returns {Promise} A promise that resolves when the batch is successfully written. * The promise should be rejected if there is an error during writing. */ protected batchWrite(chunk: BatchData): Promise; /** * Executes a batch of data in the database, commits the transaction if all * promises are resolved, or rolls back the transaction if any of the promises * are rejected. * * @private * @param {sqlite3.Database} db - The database connection. * @param {BatchData} chunk - The batch of data to write to the storage. * @returns {Promise} A promise that resolves when all promises are resolved. */ private executeBatch; /** * Commits the transaction if no errors occurred during the batch execution. * If an error occurred, the transaction is rolled back and the error is propagated. * * @private * @param {sqlite.Database} db - The database connection. * @returns {Promise} A promise that resolves when the transaction is committed. */ private commitTransaction; /** * Rolls back the transaction if an error occurred during the batch execution. * The error is propagated to the caller. * * @private * @param {sqlite.Database} db - The database connection. * @returns {Promise} A promise that resolves when the transaction is rolled back. */ private rollbackTransaction; /** * Prepares a statement for saving 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 save entities. This method should be * called when the writer is no longer needed to free up resources. * * @private */ private finalizeStatement; /** * Finalizes the writer by calling the _final method of the superclass and * finalizing the statement used to save entities. This method should be * called when the writer is no longer needed to free up resources. * @see AbstractBatchEntityWriterStream._final * @private * @param callback {WriteCallback} - The callback function to be executed after finalizing the writer. * @returns {Promise} */ _final(callback: WriteCallback): void; }