refactor cli

This commit is contained in:
Michael Hohn
2025-03-15 18:12:04 -07:00
parent 012e597d4a
commit 390dfeb087

View File

@@ -15,28 +15,28 @@ export async function extractRawResults(
const bqrsInfo = await cliServer.bqrsInfo(filePath); const bqrsInfo = await cliServer.bqrsInfo(filePath);
const resultSets = bqrsInfo["result-sets"]; const resultSets = bqrsInfo["result-sets"];
if (resultSets.length < 1) { if (resultSets.length === 0) {
throw new Error("No result sets found in results file."); throw new Error("No result sets found in results file.");
} }
if (resultSets.length > 1) { if (resultSets.length > 1) {
void logger.log( void logger.log(
"Multiple result sets found in results file. Only one will be used.", "Multiple result sets found in results file. Using the first one.",
); );
} }
// Always prefer #select over any other result set. #select is usually the result the user // Prefer `#select` result set; otherwise, use the first available set.
// wants to see since it contains the outer #select.
const schema = const schema =
resultSets.find((resultSet) => resultSet.name === SELECT_TABLE_NAME) ?? resultSets.find((r) => r.name === SELECT_TABLE_NAME) ?? resultSets[0];
resultSets[0];
const chunk = await cliServer.bqrsDecode(filePath, schema.name, { const chunk = await cliServer.bqrsDecode(filePath, schema.name, {
pageSize: MAX_RAW_RESULTS, pageSize: MAX_RAW_RESULTS,
}); });
const resultSet = bqrsToResultSet(schema, chunk); const resultSet = bqrsToResultSet(schema, chunk);
const capped = !!chunk.next; return {
resultSet,
return { resultSet, fileLinkPrefix, sourceLocationPrefix, capped }; fileLinkPrefix,
sourceLocationPrefix,
capped: !!chunk.next,
};
} }