コード例 #1
0
ファイル: magic.py プロジェクト: robcast/ipython-cypher
    def execute_graph(self, line, cell='', local_ns={}):
        """Runs Cypher statement against a Neo4j graph database, specified by
        a connect string.

        If no database connection has been established, first word
        should be a connection string, or the user@host name
        of an established connection. Otherwise, http://localhost:7474/db/data
        will be assumed.

        Examples::

          %%cyphergraph https://me:mypw@myhost:7474/db/data
          START n=node(*) RETURN n

          %%cyphergraph me@myhost
          START n=node(*) RETURN n

          %%cyphergraph
          START n=node(*) RETURN n

        Connect string syntax examples:

          http://localhost:7474/db/data
          https://me:mypw@localhost:7474/db/data

        """
        # save globals and locals so they can be referenced in bind vars
        user_ns = self.shell.user_ns
        user_ns.update(local_ns)
        parsed = parse("""{0}\n{1}""".format(line, cell), self)
        conn = Connection.get(parsed['as'] or parsed['uri'])
        first_word = parsed['cypher'].split(None, 1)[:1]
        try:
            # pass all attributes except auto_html manually to new config :-(
            conf = DefaultConfigurable(auto_html=True, 
                                       auto_limit=self.auto_limit, style=self.style, short_errors=self.short_errors,
                                       data_contents=self.data_contents, display_limit=self.display_limit, 
                                       auto_networkx=self.auto_networkx, auto_pandas=self.auto_pandas, rest=self.rest,
                                       feedback=self.feedback, uri=self.uri)
            result = run(parsed['cypher'], user_ns, conf, conn)
            return result
        except StatusException as e:
            if self.short_errors:
                print(e)
            else:
                raise
コード例 #2
0
    def execute(self, line, cell='', local_ns={}):
        """Runs Cypher statement against a Neo4j graph database, specified by
        a connect string.

        If no database connection has been established, first word
        should be a connection string, or the user@host name
        of an established connection. Otherwise, http://localhost:7474/db/data
        will be assumed.

        Examples::

          %%cypher https://me:mypw@myhost:7474/db/data
          START n=node(*) RETURN n

          %%cypher me@myhost
          START n=node(*) RETURN n

          %%cypher
          START n=node(*) RETURN n

        Connect string syntax examples:

          http://localhost:7474/db/data
          https://me:mypw@localhost:7474/db/data

        """
        # save globals and locals so they can be referenced in bind vars
        user_ns = self.shell.user_ns
        user_ns.update(local_ns)
        parsed = parse("""{0}\n{1}""".format(line, cell), self)
        conn = Connection.get(parsed['as'] or parsed['uri'], parsed['as'])
        first_word = parsed['cypher'].split(None, 1)[:1]
        if first_word and first_word[0].lower() == 'persist':
            return self._persist_dataframe(parsed['cypher'], conn, user_ns)
        try:
            result = run(parsed['cypher'], user_ns, self, conn)
            return result
        except StatusException as e:
            if self.short_errors:
                print(e)
            else:
                raise
コード例 #3
0
ファイル: magic.py プロジェクト: robcast/ipython-cypher
    def execute(self, line, cell='', local_ns={}):
        """Runs Cypher statement against a Neo4j graph database, specified by
        a connect string.

        If no database connection has been established, first word
        should be a connection string, or the user@host name
        of an established connection. Otherwise, http://localhost:7474/db/data
        will be assumed.

        Examples::

          %%cypher https://me:mypw@myhost:7474/db/data
          START n=node(*) RETURN n

          %%cypher me@myhost
          START n=node(*) RETURN n

          %%cypher
          START n=node(*) RETURN n

        Connect string syntax examples:

          http://localhost:7474/db/data
          https://me:mypw@localhost:7474/db/data

        """
        # save globals and locals so they can be referenced in bind vars
        user_ns = self.shell.user_ns
        user_ns.update(local_ns)
        parsed = parse("""{0}\n{1}""".format(line, cell), self)
        conn = Connection.get(parsed['as'] or parsed['uri'])
        first_word = parsed['cypher'].split(None, 1)[:1]
        if first_word and first_word[0].lower() == 'persist':
            return self._persist_dataframe(parsed['cypher'], conn, user_ns)
        try:
            result = run(parsed['cypher'], user_ns, self, conn)
            return result
        except StatusException as e:
            if self.short_errors:
                print(e)
            else:
                raise