Ejemplo n.º 1
0
    def connect(self, configname=None):
        """Connect to a database based upon its `nickname`.

        See ipydb.magic.connect() for details.
        """
        default, configs = engine.getconfigs()
        success = False

        def available():
            print(self.connect.__doc__)
            print("Available connection nicknames: %s" %
                  (' '.join(sorted(configs.keys()))))

        if not configname:
            available()
        elif configname not in configs:
            print("Config `%s` not found. " % configname)
            available()
        else:
            config = configs[configname]
            connect_args = {}
            success = self.connect_url(engine.make_connection_url(config),
                                       connect_args)
            if success:
                self.nickname = configname
        return success
Ejemplo n.º 2
0
    def connect(self, configname=None):
        """Connect to a database based upon its `nickname`.

        See ipydb.magic.connect() for details.
        """
        default, configs = engine.getconfigs()
        success = False

        def available():
            print(self.connect.__doc__)
            print("Available connection nicknames: %s" % (
                ' '.join(sorted(configs.keys()))))
        if not configname:
            available()
        elif configname not in configs:
            print("Config `%s` not found. " % configname)
            available()
        else:
            config = configs[configname]
            connect_args = {}
            success = self.connect_url(
                engine.make_connection_url(config), connect_args)
            if success:
                self.nickname = configname
        return success
Ejemplo n.º 3
0
 def connection_nickname(self, ev):
     """Return completions for %connect."""
     keys = sorted(getconfigs()[1].keys())
     if not ev.symbol:
         return keys
     matches = match_lists([keys], ev.symbol)
     matches.sort()
     return matches
Ejemplo n.º 4
0
 def connection_nickname(self, ev):
     """Return completions for %connect."""
     keys = sorted(getconfigs()[1].keys())
     if not ev.symbol:
         return keys
     matches = match_lists([keys], ev.symbol)
     matches.sort()
     return matches
Ejemplo n.º 5
0
    def __init__(self, shell=None, config=None):
        """Constructor.

        Args:
            shell: An instance of IPython.core.InteractiveShell.
            config: IPython's config object.
        """
        super(SqlPlugin, self).__init__(shell=shell, config=config)
        self.auto_magics = SqlMagics(self, shell)
        shell.register_magics(self.auto_magics)
        register_sql_aliases(shell.magics_manager, self.auto_magics)
        self.sqlformat = 'table'  # 'table' | 'csv'
        self.do_reflection = True
        self.connected = False
        self.engine = None
        self.nickname = None
        self.autocommit = False
        self.trans_ctx = None
        self.debug = False
        self.show_sql = False
        default, configs = engine.getconfigs()
        self.init_completer()
        if default:
            self.connect(default)
Ejemplo n.º 6
0
    def __init__(self, shell=None, config=None):
        """Constructor.

        Args:
            shell: An instance of IPython.core.InteractiveShell.
            config: IPython's config object.
        """
        super(SqlPlugin, self).__init__(shell=shell, config=config)
        self.auto_magics = SqlMagics(self, shell)
        shell.register_magics(self.auto_magics)
        register_sql_aliases(shell.magics_manager, self.auto_magics)
        self.sqlformat = 'table'  # 'table' | 'csv'
        self.do_reflection = True
        self.connected = False
        self.engine = None
        self.nickname = None
        self.autocommit = False
        self.trans_ctx = None
        self.debug = False
        self.show_sql = False
        default, configs = engine.getconfigs()
        self.init_completer()
        if default:
            self.connect(default)