-
Notifications
You must be signed in to change notification settings - Fork 203
Introduce API Redesign #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
7043662
3db7a70
c4d2c89
e0c879c
d0293e7
5d52bab
26b19a9
e3b1223
5759926
7fe9204
7896b06
9de9924
2c7004c
62fb7ae
056ac54
915875d
7af3bd9
b6fcfb2
7fb2afd
6d5e550
ed575f9
8bb4498
b64b3c8
cc875d2
0e8cbfc
ecf966f
0ad6459
a8d541f
d147e62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -392,6 +392,108 @@ async def supports_multi_db(self): | |
| await session._connect(READ_ACCESS) | ||
| return session._connection.supports_multiple_databases | ||
|
|
||
| async def query(self, query, parameters=None, **kwargs): | ||
| """ | ||
| Run a Cypher query within an managed transaction and | ||
| all the retries policy will be applied. | ||
|
|
||
| The query is sent and the result header received | ||
| immediately and the :class:`neo4j.QueryResult`is | ||
| fetched. | ||
|
|
||
| For more usage details, see :meth:`.AsyncTransaction.query`. | ||
|
|
||
| For auto-commit queries, use `AsyncSession.run`. | ||
|
|
||
| For access to the neo4j.AsyncResult object, | ||
| use `AsyncDriver.execute` and `.AsyncTransaction.run` | ||
bigmontz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| :param query: cypher query | ||
| :type query: str, neo4j.Query | ||
| :param parameters: dictionary of parameters | ||
| :type parameters: dict | ||
| :param kwargs: additional keyword parameters | ||
|
|
||
| :returns: a new :class:`neo4j.QueryResult` object | ||
| :rtype: QueryResult | ||
| """ | ||
| session_kwargs = {} | ||
| if "database" in kwargs: | ||
|
||
| session_kwargs["database"] = kwargs.pop("database") | ||
|
|
||
| async with self.session(**session_kwargs) as session: | ||
| return await session.query(query, parameters, **kwargs) | ||
|
|
||
| async def execute(self, transaction_function, *args, **kwargs): | ||
| """Execute a unit of work in a managed transaction. | ||
|
|
||
| .. note:: | ||
| This does not necessarily imply access control, see the session | ||
| configuration option :ref:`default-access-mode-ref`. | ||
robsdedude marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This transaction will automatically be committed unless an exception | ||
| is thrown during query execution or by the user code. | ||
| Note, that this function perform retries and that the supplied ` | ||
| transaction_function` might get invoked more than once. | ||
bigmontz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Managed transactions should not generally be explicitly committed | ||
| (via ``tx.commit()``). | ||
bigmontz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Example:: | ||
|
|
||
| async def do_cypher_tx(tx, cypher): | ||
| records, _ = await tx.query(cypher) | ||
| return records | ||
|
|
||
| values = await driver.execute(do_cypher_tx, "RETURN 1 AS x") | ||
|
|
||
| Example:: | ||
|
|
||
| async def do_cypher_tx(tx): | ||
| records, _ = await tx.query("RETURN 1 AS x") | ||
| return records | ||
|
|
||
| values = await driver.execute( | ||
| do_cypher_tx, | ||
| database="neo4j", | ||
| cluster_member_access=neo4j.api.CLUSTER_READERS_ACCESS | ||
| ) | ||
|
|
||
| Example:: | ||
|
|
||
| async def get_two_tx(tx): | ||
| result = await tx.run("UNWIND [1,2,3,4] AS x RETURN x") | ||
| values = [] | ||
| async for record in result: | ||
| if len(values) >= 2: | ||
| break | ||
| values.append(record.values()) | ||
| # or shorter: values = [record.values() | ||
| # for record in await result.fetch(2)] | ||
|
|
||
| # discard the remaining records if there are any | ||
| summary = await result.consume() | ||
| # use the summary for logging etc. | ||
| return values | ||
|
|
||
|
|
||
| values = await driver.execute(get_two_tx) | ||
|
|
||
| :param transaction_function: a function that takes a transaction as an | ||
| argument and does work with the transaction. | ||
| ``transaction_function(tx, *args, **kwargs)`` where ``tx`` is a | ||
| :class:`.Transaction`. | ||
| :param args: arguments for the ``transaction_function`` | ||
| :param kwargs: key word arguments for the ``transaction_function`` | ||
| :return: a result as returned by the given unit of work | ||
bigmontz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| session_kwargs = {} | ||
| if "database" in kwargs: | ||
| session_kwargs["database"] = kwargs.pop("database") | ||
|
|
||
| async with self.session(**session_kwargs) as session: | ||
| return await session.execute(transaction_function, *args, **kwargs) | ||
|
|
||
|
|
||
| class AsyncBoltDriver(_Direct, AsyncDriver): | ||
| """:class:`.AsyncBoltDriver` is instantiated for ``bolt`` URIs and | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.