ibrowser.py
author Radek Brich <radek.brich@devl.cz>
Mon, 09 Dec 2013 11:39:28 +0100
changeset 91 fba99a54ec49
parent 52 26121a8fe78b
child 104 d8ff52a0390f
permissions -rwxr-xr-x
Add to runquery tool: Parameters for query, output file and format for output file. Fix loopquery tool.

#!/usr/bin/env python3
"""
interactive schema browser

Connect to specified database and open interactive shell.

PgBrowser instance is "browser".

Example:

>>> browser.schemas['myschema'].tables['mytable'].columns['id'].default
"nextval('mytable_id_seq'::regclass)"

"""

from pgtoolkit import pgbrowser, toolbase

import code


class InteractiveBrowserTool(toolbase.SimpleTool):
    def __init__(self):
        toolbase.SimpleTool.__init__(self, name='ibrowser', desc='Interactive schema browser.')
        self.init()

    def main(self):
        browser = pgbrowser.PgBrowser(self.pgm.get_conn('target'))
        shell = code.InteractiveConsole(locals())
        shell.interact()


tool = InteractiveBrowserTool()
tool.main()