|  | 
| 43 | 43 | ) | 
| 44 | 44 | from ..addressing import Address | 
| 45 | 45 | from ..api import ( | 
|  | 46 | +    AsyncBookmarkManager, | 
| 46 | 47 |     Auth, | 
|  | 48 | +    BookmarkManager, | 
| 47 | 49 |     Bookmarks, | 
| 48 | 50 |     DRIVER_BOLT, | 
| 49 | 51 |     DRIVER_NEO4J, | 
|  | 
| 62 | 64 |     URI_SCHEME_NEO4J_SECURE, | 
| 63 | 65 |     URI_SCHEME_NEO4J_SELF_SIGNED_CERTIFICATE, | 
| 64 | 66 | ) | 
|  | 67 | +from .bookmark_manager import AsyncNeo4jBookmarkManager | 
| 65 | 68 | from .work import AsyncSession | 
| 66 | 69 | 
 | 
| 67 | 70 | 
 | 
|  | 71 | +_T_BmSupplier = t.Callable[[str], t.Union[Bookmarks, t.Awaitable[Bookmarks]]] | 
|  | 72 | +_T_NotifyBm = t.Callable[[str, Bookmarks], t.Union[None, t.Awaitable[None]]] | 
|  | 73 | + | 
|  | 74 | + | 
| 68 | 75 | class AsyncGraphDatabase: | 
| 69 | 76 |     """Accessor for :class:`neo4j.Driver` construction. | 
| 70 | 77 |     """ | 
| @@ -94,6 +101,8 @@ def driver( | 
| 94 | 101 |             ssl_context: ssl.SSLContext = ..., | 
| 95 | 102 |             user_agent: str = ..., | 
| 96 | 103 |             keep_alive: bool = ..., | 
|  | 104 | +            bookmark_manager: t.Union[AsyncBookmarkManager, | 
|  | 105 | +                                      BookmarkManager, None] = ..., | 
| 97 | 106 | 
 | 
| 98 | 107 |             # undocumented/unsupported options | 
| 99 | 108 |             # they may be change or removed any time without prior notice | 
| @@ -208,6 +217,36 @@ def driver(cls, uri, *, auth=None, **config) -> AsyncDriver: | 
| 208 | 217 |             return cls.neo4j_driver(parsed.netloc, auth=auth, | 
| 209 | 218 |                                     routing_context=routing_context, **config) | 
| 210 | 219 | 
 | 
|  | 220 | +    @classmethod | 
|  | 221 | +    def bookmark_manager( | 
|  | 222 | +        cls, initial_bookmarks: Bookmarks = None, | 
|  | 223 | +        bookmark_supplier: _T_BmSupplier = None, | 
|  | 224 | +        notify_bookmarks: _T_NotifyBm = None | 
|  | 225 | +    ) -> AsyncBookmarkManager: | 
|  | 226 | +        """Create a default :class:`AsyncBookmarkManager`. | 
|  | 227 | +
 | 
|  | 228 | +        :param initial_bookmarks: | 
|  | 229 | +            The initial set of bookmarks. The default bookmark manager will | 
|  | 230 | +            seed the set of bookmarks for each database with this value. | 
|  | 231 | +        :param bookmark_supplier: | 
|  | 232 | +            Function which will be called every time the default bookmark | 
|  | 233 | +            manager's method :meth:`.AsyncBookmarkManager.get_bookmarks` | 
|  | 234 | +            gets called. The result of ``bookmark_supplier`` will be | 
|  | 235 | +            concatenated with the internal set of bookmarks and used to | 
|  | 236 | +            configure the session in creation. | 
|  | 237 | +        :param notify_bookmarks: | 
|  | 238 | +            Function which will be called whenever the set of bookmarks | 
|  | 239 | +            handled by the bookmark manager gets updated with the new | 
|  | 240 | +            internal bookmark set. | 
|  | 241 | +
 | 
|  | 242 | +        :returns: A default implementation of :class:`AsyncBookmarkManager`. | 
|  | 243 | +        """ | 
|  | 244 | +        return AsyncNeo4jBookmarkManager( | 
|  | 245 | +            initial_bookmarks=initial_bookmarks, | 
|  | 246 | +            bookmark_supplier=bookmark_supplier, | 
|  | 247 | +            notify_bookmarks=notify_bookmarks | 
|  | 248 | +        ) | 
|  | 249 | + | 
| 211 | 250 |     @classmethod | 
| 212 | 251 |     def bolt_driver(cls, target, *, auth=None, **config): | 
| 213 | 252 |         """ Create a driver for direct Bolt server access that uses | 
| @@ -353,6 +392,8 @@ def session( | 
| 353 | 392 |             initial_retry_delay: float = ..., | 
| 354 | 393 |             retry_delay_multiplier: float = ..., | 
| 355 | 394 |             retry_delay_jitter_factor: float = ..., | 
|  | 395 | +            bookmark_manager: t.Union[AsyncBookmarkManager, | 
|  | 396 | +                                      BookmarkManager, None] = ..., | 
| 356 | 397 |         ) -> AsyncSession: | 
| 357 | 398 |             ... | 
| 358 | 399 | 
 | 
| @@ -394,6 +435,8 @@ async def verify_connectivity( | 
| 394 | 435 |             initial_retry_delay: float = ..., | 
| 395 | 436 |             retry_delay_multiplier: float = ..., | 
| 396 | 437 |             retry_delay_jitter_factor: float = ..., | 
|  | 438 | +            bookmark_manager: t.Union[AsyncBookmarkManager, | 
|  | 439 | +                                      BookmarkManager, None] = ..., | 
| 397 | 440 |         ) -> None: | 
| 398 | 441 |             ... | 
| 399 | 442 | 
 | 
| @@ -456,6 +499,8 @@ async def get_server_info( | 
| 456 | 499 |             initial_retry_delay: float = ..., | 
| 457 | 500 |             retry_delay_multiplier: float = ..., | 
| 458 | 501 |             retry_delay_jitter_factor: float = ..., | 
|  | 502 | +            bookmark_manager: t.Union[AsyncBookmarkManager, | 
|  | 503 | +                                      BookmarkManager, None] = ..., | 
| 459 | 504 |         ) -> ServerInfo: | 
| 460 | 505 |             ... | 
| 461 | 506 | 
 | 
|  | 
0 commit comments