in src/GetDocument.ts [178:214]
export async function getDocumentIdsAndVersions(
txn: TransactionExecutor,
tableName: string,
keyAttributeName: string,
keyAttributeValue: string
): Promise<GetDocIdAndVersionResult[]> {
const fcnName = "[GetDocument.getDocumentIdsAndVersions]"
const startTime: number = new Date().getTime();
validateTableNameConstrains(tableName);
validateAttributeNameConstrains(keyAttributeName);
const query = `SELECT metadata.id, metadata.version FROM _ql_committed_${tableName} AS t BY id WHERE t.data.${keyAttributeName} = ?`;
let documentIds: GetDocIdAndVersionResult[] = [];
try {
const result: Result = await txn.execute(query, keyAttributeValue);
const resultList: dom.Value[] = result.getResultList();
if (resultList.length === 0) {
throw `Unable to retrieve document ID using ${keyAttributeValue}.`
}
resultList.forEach(async (result, index) => {
let id: string = resultList[index].get("id").stringValue();
let version: number = resultList[index].get("version").numberValue();
documentIds.push({
id: id,
version: version
});
})
return documentIds;
} catch (err) {
const endTime: number = new Date().getTime();
logger.debug(`${fcnName} Execution time: ${endTime - startTime}ms`)
throw new Error(`${fcnName} ${err}`);
}
}