in src/QLDBHelper.ts [47:81]
export async function createTableWithIndex(qldbDriver: QldbDriver, tableName: string, keyAttributeName: string): Promise<number> {
const fcnName = "[QLDBHelper.createTableWithIndex]"
try {
//// Listing tables names
const tableNames: string[] = await listTables(qldbDriver);
//// Checking if table is already created and create if not
logger.debug(`${fcnName} Checking if table with name ${tableName} exists`);
if (tableNames.indexOf(tableName.toUpperCase()) < 0) {
// Creating table
return qldbDriver.executeLambda(async (txn: TransactionExecutor) => {
let resultsTotal = 0;
validateTableNameConstrains(tableName);
const statement = `CREATE TABLE ${tableName}`;
const resultCreateTable: Result = await txn.execute(statement)
logger.info(`${fcnName} Successfully created table ${tableName}. Creating index.`);
resultsTotal += resultCreateTable.getResultList().length;
validateAttributeNameConstrains(keyAttributeName);
const createIndexStatement = `CREATE INDEX on ${tableName} (${keyAttributeName})`;
const resultCreateIndex: Result = await txn.execute(createIndexStatement)
logger.info(`${fcnName} Successfully created index ${keyAttributeName} on table ${tableName}.`);
resultsTotal += resultCreateIndex.getResultList().length;
return resultsTotal;
});
} else {
logger.debug(`${fcnName} Table with name "${tableName}" already exists`);
return 0;
}
} catch (err) {
throw new Error(`${fcnName} ${err}`)
}
}