equal
deleted
inserted
replaced
1 #!/usr/bin/env python3 |
|
2 |
|
3 from pgtoolkit import pgbrowser, toolbase |
|
4 |
|
5 |
|
6 class ListDependsTool(toolbase.SimpleTool): |
|
7 def __init__(self): |
|
8 toolbase.SimpleTool.__init__(self, name='listdepends', desc='List column dependencies.') |
|
9 self.parser.add_argument('table', metavar='table', type=str, help='Table name.') |
|
10 self.parser.add_argument('column', metavar='column', type=str, help='Column name.') |
|
11 self.parser.add_argument('-s', '--schema', dest='schema', metavar='schema', |
|
12 type=str, default='public', help='Schema name (default=public).') |
|
13 self.init() |
|
14 |
|
15 def main(self): |
|
16 browser = pgbrowser.PgBrowser(self.pgm.get_conn('target')) |
|
17 |
|
18 objects = browser.list_column_usage(self.args.table, self.args.column, schema=self.args.schema) |
|
19 for obj in sorted(objects, key=lambda x: (x['type'], x['schema'], x['name'])): |
|
20 print(obj['type'], ' ', obj['schema'], '.', obj['name'], sep='') |
|
21 |
|
22 |
|
23 tool = ListDependsTool() |
|
24 tool.main() |
|
25 |
|