コード例 #1
0
ファイル: perf.py プロジェクト: timgates42/py2neo
def run(uri, auth=None, routing=False, secure=False):
    """ Run one or more Cypher queries through the client console, or
    open the console for interactive use if no queries are specified.
    """
    profile = ConnectionProfile(uri, auth=auth, secure=secure)
    g = Graph(profile, routing=routing)
    result = [()]

    def iterate_result():
        for _ in result[0]:
            pass

    scale = 250000
    print("Scale = {}".format(scale))

    ##########
    # TEST 1 #
    ##########

    def run_long_narrow(p):
        p.result = p.graph.run("UNWIND range(1, $n) AS _ "
                               "RETURN 0",
                               pull=scale)

    print("Iterating long narrow result... ", end="", flush=True)
    print("{:.03f}s".format(
        ResultIterationPerformer(profile, run_long_narrow).run()))

    ##########
    # TEST 2 #
    ##########

    def run_long_triple_string(p):
        p.result = p.graph.run(
            "UNWIND range(1, $n) AS _ RETURN 'aaaaaaaaa' AS a, "
            "'bbbbbbbbb' AS b, 'ccccccccc' AS c",
            pull=scale)

    print("Iterating long triple string result... ", end="", flush=True)
    print("{:.03f}s".format(
        ResultIterationPerformer(profile, run_long_triple_string).run()))

    ##########
    # TEST 3 #
    ##########

    def run_long_multi_type(p):
        p.result = p.graph.run(
            "UNWIND range(1, $n) AS _ RETURN null, true, 0, 3.14, "
            "'Abc', [1, 2, 3], {one: 1, two: 2, three: 3}",
            pull=scale)

    print("Iterating long multi-type result... ", end="", flush=True)
    print("{:.03f}s".format(
        ResultIterationPerformer(profile, run_long_multi_type).run()))
コード例 #2
0
    def __init__(self, profile=None, *_, **settings):
        super(ClientConsole, self).__init__(__name__, verbosity=settings.get("verbosity", 0))
        self.output_file = settings.pop("file", None)

        welcome = settings.get("welcome", True)
        if welcome:
            self.write(TITLE)
            self.write()
            self.write(dedent(QUICK_HELP))
            self.write()

        self.profile = ConnectionProfile(profile, **settings)
        try:
            self.graph = Graph(self.profile)
        except OSError as error:
            self.critical("Could not connect to <%s> (%s)", self.profile.uri, " ".join(map(str, error.args)))
            raise
        else:
            self.debug("Connected to <%s>", self.graph.service.uri)
        try:
            makedirs(HISTORY_FILE_DIR)
        except OSError:
            pass
        self.history = FileHistory(path_join(HISTORY_FILE_DIR, HISTORY_FILE))
        self.lexer = CypherLexer()
        self.result_writer = Table.write

        self.commands = {

            "//": self.set_multi_line,
            "/e": self.edit,

            "/?": self.help,
            "/h": self.help,
            "/help": self.help,

            "/x": self.exit,
            "/exit": self.exit,

            "/play": self.play,

            "/csv": self.set_csv_result_writer,
            "/table": self.set_tabular_result_writer,
            "/tsv": self.set_tsv_result_writer,

            "/config": self.config,
            "/kernel": self.kernel,

        }
        self.tx = None
        self.qid = 0
コード例 #3
0
ファイル: conftest.py プロジェクト: pkla/py2neo
def connection_profile(uri):
    return ConnectionProfile(uri)