Skip to content

Commit 212cfd4

Browse files
robsdedudefbivillebigmontz
authored
[ADR-001] bookmark manager (neo4j#771)
Co-authored-by: Florent Biville <[email protected]> Co-authored-by: Antonio Barcelos <[email protected]>
1 parent a13bdc6 commit 212cfd4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3017
-411
lines changed

bin/make-unasync

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ class CustomRule(unasync.Rule):
154154
start += 1
155155
end += 1
156156
else:
157-
out += self._unasync_prefix(name[start:(end - 1)])
157+
out += self._unasync_name(name[start:(end - 1)])
158158
start = end - 1
159159

160160
sub_name = name[start:]
161161
if sub_name.isidentifier():
162-
out += self._unasync_prefix(name[start:])
162+
out += self._unasync_name(name[start:])
163163
else:
164164
out += sub_name
165165

@@ -221,6 +221,7 @@ def apply_unasync(files):
221221
"mark_async_test": "mark_sync_test",
222222
"assert_awaited_once": "assert_called_once",
223223
"assert_awaited_once_with": "assert_called_once_with",
224+
"await_count": "call_count",
224225
}
225226
additional_testkit_backend_replacements = {}
226227
rules = [

docs/source/api.rst

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,41 @@ Driver Construction
1414
The :class:`neo4j.Driver` construction is done via a ``classmethod`` on the :class:`neo4j.GraphDatabase` class.
1515

1616
.. autoclass:: neo4j.GraphDatabase
17-
:members: driver
17+
:members: bookmark_manager
1818

19+
.. method:: driver
1920

20-
Driver creation example:
21+
Driver creation example:
2122

22-
.. code-block:: python
23+
.. code-block:: python
2324
24-
from neo4j import GraphDatabase
25+
from neo4j import GraphDatabase
2526
26-
uri = "neo4j://example.com:7687"
27-
driver = GraphDatabase.driver(uri, auth=("neo4j", "password"))
27+
uri = "neo4j://example.com:7687"
28+
driver = GraphDatabase.driver(uri, auth=("neo4j", "password"))
2829
29-
driver.close() # close the driver object
30+
driver.close() # close the driver object
3031
3132
32-
For basic authentication, ``auth`` can be a simple tuple, for example:
33+
For basic authentication, ``auth`` can be a simple tuple, for example:
3334

34-
.. code-block:: python
35+
.. code-block:: python
3536
36-
auth = ("neo4j", "password")
37+
auth = ("neo4j", "password")
3738
38-
This will implicitly create a :class:`neo4j.Auth` with a ``scheme="basic"``.
39-
Other authentication methods are described under :ref:`auth-ref`.
39+
This will implicitly create a :class:`neo4j.Auth` with a ``scheme="basic"``.
40+
Other authentication methods are described under :ref:`auth-ref`.
4041

4142

42-
``with`` block context example:
43+
``with`` block context example:
4344

44-
.. code-block:: python
45+
.. code-block:: python
4546
46-
from neo4j import GraphDatabase
47+
from neo4j import GraphDatabase
4748
48-
uri = "neo4j://example.com:7687"
49-
with GraphDatabase.driver(uri, auth=("neo4j", "password")) as driver:
50-
# use the driver
49+
uri = "neo4j://example.com:7687"
50+
with GraphDatabase.driver(uri, auth=("neo4j", "password")) as driver:
51+
# use the driver
5152
5253
5354
@@ -138,7 +139,7 @@ Alternatively, one of the auth token helper functions can be used.
138139
Driver
139140
******
140141

141-
Every Neo4j-backed application will require a :class:`neo4j.Driver` object.
142+
Every Neo4j-backed application will require a driver object.
142143

143144
This object holds the details required to establish connections with a Neo4j database, including server URIs, credentials and other configuration.
144145
:class:`neo4j.Driver` objects hold a connection pool from which :class:`neo4j.Session` objects can borrow connections.
@@ -274,6 +275,7 @@ Specify whether TCP keep-alive should be enabled.
274275
:Default: ``True``
275276

276277
**This is experimental.** (See :ref:`filter-warnings-ref`)
278+
It might be changed or removed any time even without prior notice.
277279

278280

279281
.. _max-connection-lifetime-ref:
@@ -576,6 +578,7 @@ To construct a :class:`neo4j.Session` use the :meth:`neo4j.Driver.session` metho
576578
+ :ref:`database-ref`
577579
+ :ref:`default-access-mode-ref`
578580
+ :ref:`fetch-size-ref`
581+
+ :ref:`bookmark-manager-ref`
579582

580583

581584
.. _bookmarks-ref:
@@ -704,6 +707,33 @@ The fetch size used for requesting messages from Neo4j.
704707
:Default: ``1000``
705708

706709

710+
.. _bookmark-manager-ref:
711+
712+
``bookmark_manager``
713+
--------------------
714+
Specify a bookmark manager for the session to use. If present, the bookmark
715+
manager is used to keep all work within the session causally consistent with
716+
all work in other sessions using the same bookmark manager.
717+
718+
See :class:`.BookmarkManager` for more information.
719+
720+
.. warning::
721+
Enabling the BookmarkManager can have a negative impact on performance since
722+
all queries will wait for the latest changes to be propagated across the
723+
cluster.
724+
725+
For simple use-cases, it often suffices that work within a single session
726+
is automatically causally consistent.
727+
728+
:Type: :const:`None` or :class:`.BookmarkManager`
729+
:Default: :const:`None`
730+
731+
.. versionadded:: 5.0
732+
733+
**This is experimental.** (See :ref:`filter-warnings-ref`)
734+
It might be changed or removed any time even without prior notice.
735+
736+
707737

708738

709739
***********
@@ -829,7 +859,7 @@ Returning a live result object would prevent the driver from correctly managing
829859

830860
This function will receive a :class:`neo4j.ManagedTransaction` object as its first parameter.
831861

832-
.. autoclass:: neo4j.ManagedTransaction
862+
.. autoclass:: neo4j.ManagedTransaction()
833863

834864
.. automethod:: run
835865

@@ -911,6 +941,7 @@ Graph
911941
.. automethod:: relationship_type
912942

913943
**This is experimental.** (See :ref:`filter-warnings-ref`)
944+
It might be changed or removed any time even without prior notice.
914945

915946

916947
******
@@ -1231,6 +1262,14 @@ Temporal Data Types
12311262
See topic :ref:`temporal-data-types` for more details.
12321263

12331264

1265+
***************
1266+
BookmarkManager
1267+
***************
1268+
1269+
.. autoclass:: neo4j.api.BookmarkManager
1270+
:members:
1271+
1272+
12341273
.. _errors-ref:
12351274

12361275
******
@@ -1526,6 +1565,7 @@ Bookmarks
15261565

15271566
.. autoclass:: neo4j.Bookmarks
15281567
:members:
1568+
:special-members: __bool__, __add__, __iter__
15291569

15301570
.. autoclass:: neo4j.Bookmark
15311571
:members:

docs/source/async_api.rst

Lines changed: 67 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,53 @@ Async Driver Construction
2121
The :class:`neo4j.AsyncDriver` construction is done via a ``classmethod`` on the :class:`neo4j.AsyncGraphDatabase` class.
2222

2323
.. autoclass:: neo4j.AsyncGraphDatabase
24-
:members: driver
24+
:members: bookmark_manager
2525

26+
.. automethod:: driver
2627

27-
Driver creation example:
28+
Driver creation example:
2829

29-
.. code-block:: python
30+
.. code-block:: python
3031
31-
import asyncio
32+
import asyncio
3233
33-
from neo4j import AsyncGraphDatabase
34+
from neo4j import AsyncGraphDatabase
3435
35-
async def main():
36-
uri = "neo4j://example.com:7687"
37-
driver = AsyncGraphDatabase.driver(uri, auth=("neo4j", "password"))
36+
async def main():
37+
uri = "neo4j://example.com:7687"
38+
driver = AsyncGraphDatabase.driver(uri, auth=("neo4j", "password"))
3839
39-
await driver.close() # close the driver object
40+
await driver.close() # close the driver object
4041
41-
asyncio.run(main())
42+
asyncio.run(main())
4243
4344
44-
For basic authentication, ``auth`` can be a simple tuple, for example:
45+
For basic authentication, ``auth`` can be a simple tuple, for example:
4546

46-
.. code-block:: python
47+
.. code-block:: python
4748
48-
auth = ("neo4j", "password")
49+
auth = ("neo4j", "password")
4950
50-
This will implicitly create a :class:`neo4j.Auth` with a ``scheme="basic"``.
51-
Other authentication methods are described under :ref:`auth-ref`.
51+
This will implicitly create a :class:`neo4j.Auth` with a ``scheme="basic"``.
52+
Other authentication methods are described under :ref:`auth-ref`.
5253

53-
``with`` block context example:
54+
``with`` block context example:
5455

55-
.. code-block:: python
56+
.. code-block:: python
5657
57-
import asyncio
58+
import asyncio
5859
59-
from neo4j import AsyncGraphDatabase
60+
from neo4j import AsyncGraphDatabase
6061
61-
async def main():
62-
uri = "neo4j://example.com:7687"
63-
auth = ("neo4j", "password")
64-
async with AsyncGraphDatabase.driver(uri, auth=auth) as driver:
65-
# use the driver
66-
...
62+
async def main():
63+
uri = "neo4j://example.com:7687"
64+
auth = ("neo4j", "password")
65+
async with AsyncGraphDatabase.driver(uri, auth=auth) as driver:
66+
# use the driver
67+
...
68+
69+
asyncio.run(main())
6770
68-
asyncio.run(main())
6971
7072
7173
.. _async-uri-ref:
@@ -120,7 +122,7 @@ Each supported scheme maps to a particular :class:`neo4j.AsyncDriver` subclass t
120122
AsyncDriver
121123
***********
122124

123-
Every Neo4j-backed application will require a :class:`neo4j.AsyncDriver` object.
125+
Every Neo4j-backed application will require a driver object.
124126

125127
This object holds the details required to establish connections with a Neo4j database, including server URIs, credentials and other configuration.
126128
:class:`neo4j.AsyncDriver` objects hold a connection pool from which :class:`neo4j.AsyncSession` objects can borrow connections.
@@ -144,6 +146,7 @@ Async Driver Configuration
144146
(see :ref:`driver-configuration-ref`). The only difference is that the async
145147
driver accepts an async custom resolver function:
146148

149+
147150
.. _async-resolver-ref:
148151

149152
``resolver``
@@ -366,7 +369,35 @@ Session Configuration
366369
=====================
367370

368371
:class:`neo4j.AsyncSession` is configured exactly like :class:`neo4j.Session`
369-
(see :ref:`session-configuration-ref`).
372+
(see :ref:`session-configuration-ref`). The only difference is the async session
373+
accepts either a :class:`neo4j.api.BookmarkManager` object or a
374+
:class:`neo4j.api.AsyncBookmarkManager` as bookmark manager:
375+
376+
377+
.. _async-bookmark-manager-ref:
378+
379+
``bookmark_manager``
380+
--------------------
381+
Specify a bookmark manager for the driver to use. If present, the bookmark
382+
manager is used to keep all work on the driver causally consistent.
383+
384+
See :class:`BookmarkManager` for more information.
385+
386+
.. warning::
387+
Enabling the BookmarkManager can have a negative impact on performance since
388+
all queries will wait for the latest changes to be propagated across the
389+
cluster.
390+
391+
For simpler use-cases, sessions (:class:`.AsyncSession`) can be used to
392+
group a series of queries together that will be causally chained
393+
automatically.
394+
395+
:Type: :const:`None`, :class:`BookmarkManager`, or :class:`AsyncBookmarkManager`
396+
:Default: :const:`None`
397+
398+
**This is experimental.** (See :ref:`filter-warnings-ref`)
399+
It might be changed or removed any time even without prior notice.
400+
370401

371402

372403
****************
@@ -501,7 +532,7 @@ Returning a live result object would prevent the driver from correctly managing
501532

502533
This function will receive a :class:`neo4j.AsyncManagedTransaction` object as its first parameter.
503534

504-
.. autoclass:: neo4j.AsyncManagedTransaction
535+
.. autoclass:: neo4j.AsyncManagedTransaction()
505536

506537
.. automethod:: run
507538

@@ -522,7 +553,6 @@ Example:
522553
To exert more control over how a transaction function is carried out, the :func:`neo4j.unit_of_work` decorator can be used.
523554

524555

525-
526556
***********
527557
AsyncResult
528558
***********
@@ -568,6 +598,13 @@ A :class:`neo4j.AsyncResult` is attached to an active connection, through a :cla
568598
See https://neo4j.com/docs/python-manual/current/cypher-workflow/#python-driver-type-mapping for more about type mapping.
569599

570600

601+
********************
602+
AsyncBookmarkManager
603+
********************
604+
605+
.. autoclass:: neo4j.api.AsyncBookmarkManager
606+
:members:
607+
571608

572609
******************
573610
Async Cancellation

0 commit comments

Comments
 (0)