1 | 'use strict'
|
2 |
|
3 | const co = require('co')
|
4 | const cli = require('heroku-cli-util')
|
5 | const pg = require('heroku-pg')
|
6 |
|
7 | function * run (context, heroku) {
|
8 | let db = yield pg.fetcher(heroku).database(context.app, context.args.database)
|
9 |
|
10 | let query = `
|
11 | SELECT
|
12 | relname AS name,
|
13 | n_live_tup AS estimated_count
|
14 | FROM
|
15 | pg_stat_user_tables
|
16 | ORDER BY
|
17 | n_live_tup DESC;
|
18 | `
|
19 |
|
20 | let output = yield pg.psql.exec(db, query)
|
21 | process.stdout.write(output)
|
22 | }
|
23 |
|
24 | const 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 |
|
33 | module.exports = [
|
34 | Object.assign({command: 'records-rank'}, cmd),
|
35 | Object.assign({command: 'records_rank', hidden: true}, cmd)
|
36 | ]
|