UNPKG

821 BJavaScriptView Raw
1'use strict'
2
3const co = require('co')
4const cli = require('heroku-cli-util')
5const pg = require('heroku-pg')
6
7function * run (context, heroku) {
8 let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
9
10 let query = `
11SELECT
12 relname AS name,
13 n_live_tup AS estimated_count
14FROM
15 pg_stat_user_tables
16ORDER BY
17 n_live_tup DESC;
18`
19
20 let output = yield pg.psql.exec(db, query)
21 process.stdout.write(output)
22}
23
24const cmd = {
25 topic: 'pg',
26 description: 'show all tables and the number of rows in each ordered by number of rows descending',
27 needsApp: true,
28 needsAuth: true,
29 args: [{name: 'database', optional: true}],
30 run: cli.command(co.wrap(run))
31}
32
33module.exports = [
34 Object.assign({command: 'records-rank'}, cmd),
35 Object.assign({command: 'records_rank', hidden: true}, cmd)
36]