pgtoolkit/tools/listdepends.py
changeset 101 2a2d0d5df03b
parent 93 b72591087495
equal deleted inserted replaced
100:d6088dba8fea 101:2a2d0d5df03b
       
     1 from pgtoolkit.toolbase import SimpleTool
       
     2 from pgtoolkit import pgbrowser
       
     3 
       
     4 
       
     5 class ListDependsTool(SimpleTool):
       
     6 
       
     7     """
       
     8     List column dependencies.
       
     9 
       
    10     """
       
    11 
       
    12     def __init__(self):
       
    13         SimpleTool.__init__(self, name='listdepends')
       
    14 
       
    15     def specify_args(self):
       
    16         SimpleTool.specify_args(self)
       
    17         self.parser.add_argument('table', metavar='table', type=str, help='Table name.')
       
    18         self.parser.add_argument('column', metavar='column', type=str, help='Column name.')
       
    19         self.parser.add_argument('-s', '--schema', dest='schema', metavar='schema',
       
    20             type=str, default='public', help='Schema name (default=public).')
       
    21 
       
    22     def main(self):
       
    23         browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
       
    24 
       
    25         objects = browser.list_column_usage(self.args.table, self.args.column, schema=self.args.schema)
       
    26         for obj in sorted(objects, key=lambda x: (x['type'], x['schema'], x['name'])):
       
    27             print(obj['type'], ' ', obj['schema'], '.', obj['name'], sep='')
       
    28 
       
    29 
       
    30 cls = ListDependsTool
       
    31