async getHistory()

in src/QLDBKVS.ts [566:601]


    async getHistory(key: string, fromDateISO?: string, toDateISO?: string): Promise<object[]> {
        const fcnName = "[QLDBKVS.getHistory]";
        const self: QLDBKVS = this;
        const ledgerName: string = self.ledgerName;
        const tableName: string = self.tableName;
        const paramId: string = key;
        const startTime: number = new Date().getTime();
        try {
            if (!paramId) {
                throw new Error(`${fcnName}: Please specify a key`);
            }

            logger.debug(`${fcnName} Getting history for ${paramId} from ledger ${ledgerName} and table ${tableName} into a JSON object`);

            const result: object[] = await this.qldbDriver.executeLambda(async (txn: TransactionExecutor) => {
                return await getDocumentHistory(txn, tableName, KEY_ATTRIBUTE_NAME, paramId, fromDateISO, toDateISO).catch((err) => {
                    throw err
                });
            })

            if (!result) {
                throw `Requested document does not exist`;
            }

            return result;

        } catch (err) {
            const msg = `Could not get history`;
            logger.error(`${fcnName} ${msg}: ${err}`);
            throw new Error(msg);
        } finally {
            const endTime: number = new Date().getTime();
            logger.debug(`${fcnName} Execution time: ${endTime - startTime}ms`)
        }

    }