UNPKG

@rockset/cli

Version:
57 lines (56 loc) 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // Generated file, please do not edit directly const core_1 = require("@oclif/core"); const base_command_1 = require("../base-command"); const core_2 = require("@rockset/core"); const _ = require("lodash"); const inquirer = require("inquirer"); const cli_ux_1 = require("cli-ux"); const util_1 = require("../helper/util"); let SQL = /** @class */ (() => { class SQL extends base_command_1.RockCommand { async run() { const { args, flags } = await this.parse(SQL); const sql = args.sql; const execute = async (sql) => { var _a; const client = await core_2.main.createClient(); if (sql && _.isString(sql)) { const data = await client.queries.query({ sql: { query: sql, default_row_limit: flags.defaultLimit, }, }); const unwrapData = (_a = data === null || data === void 0 ? void 0 : data.results) !== null && _a !== void 0 ? _a : []; util_1.showTable(unwrapData, flags); } }; if (sql) { await execute(sql); } else { const type = 'editor'; const sql = await inquirer.prompt([{ name: 'sql', type }]); await execute(sql.sql); } } } SQL.flags = Object.assign({ help: core_1.Flags.help({ char: 'h' }), defaultLimit: core_1.Flags.integer({ char: 'l', description: 'set the default row limit property on the query. This will set a default limit on the query that can be overrided by a limit in the SQL text.', }) }, cli_ux_1.cli.table.flags({ only: ['columns', 'output'] })); SQL.args = [ { name: 'sql', description: 'rockset SQL string to execute', required: false, hidden: false, }, ]; SQL.examples = [`rockset sql "Select 'hello world'"`, `rockset sql`]; SQL.description = `execute a SQL expression`; return SQL; })(); exports.default = SQL;