databricks-cli
Version:
A CLI tool for quick Databricks tasks
35 lines (34 loc) • 1.28 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.selectDatabase = selectDatabase;
exports.selectTable = selectTable;
const prompts_1 = require("@inquirer/prompts");
const connection_1 = require("./connection");
async function selectDatabase() {
const session = await (0, connection_1.getSharedSession)();
const query = "SHOW DATABASES";
const operation = await session.executeStatement(query);
const databases = await operation.fetchAll();
const databaseChoices = databases.map((db) => ({
value: db.databaseName || db[0],
name: db.databaseName || db[0],
}));
return await (0, prompts_1.select)({
message: "Select a database:",
choices: databaseChoices,
});
}
async function selectTable(database) {
const session = await (0, connection_1.getSharedSession)();
const query = `SHOW TABLES IN ${database}`;
const operation = await session.executeStatement(query);
const tables = await operation.fetchAll();
const tableChoices = tables.map((table) => ({
value: table.tableName || table[0],
name: table.tableName || table[0],
}));
return await (0, prompts_1.select)({
message: "Select a table:",
choices: tableChoices,
});
}
;