4747 experimental_warn ,
4848 unclosed_resource_warn ,
4949)
50- from .._work import EagerResult
50+ from .._work import (
51+ EagerResult ,
52+ Query ,
53+ unit_of_work ,
54+ )
5155from ..addressing import Address
5256from ..api import (
5357 AsyncBookmarkManager ,
@@ -581,7 +585,7 @@ async def close(self) -> None:
581585 @t .overload
582586 async def execute_query (
583587 self ,
584- query_ : te .LiteralString ,
588+ query_ : t . Union [ te .LiteralString , Query ] ,
585589 parameters_ : t .Optional [t .Dict [str , t .Any ]] = None ,
586590 routing_ : T_RoutingControl = RoutingControl .WRITE ,
587591 database_ : t .Optional [str ] = None ,
@@ -600,7 +604,7 @@ async def execute_query(
600604 @t .overload
601605 async def execute_query (
602606 self ,
603- query_ : te .LiteralString ,
607+ query_ : t . Union [ te .LiteralString , Query ] ,
604608 parameters_ : t .Optional [t .Dict [str , t .Any ]] = None ,
605609 routing_ : T_RoutingControl = RoutingControl .WRITE ,
606610 database_ : t .Optional [str ] = None ,
@@ -618,7 +622,7 @@ async def execute_query(
618622
619623 async def execute_query (
620624 self ,
621- query_ : te .LiteralString ,
625+ query_ : t . Union [ te .LiteralString , Query ] ,
622626 parameters_ : t .Optional [t .Dict [str , t .Any ]] = None ,
623627 routing_ : T_RoutingControl = RoutingControl .WRITE ,
624628 database_ : t .Optional [str ] = None ,
@@ -651,8 +655,9 @@ async def execute_query(
651655 query_, parameters_, routing_, database_, impersonated_user_,
652656 bookmark_manager_, auth_, result_transformer_, **kwargs
653657 ):
658+ @unit_of_work(query_.metadata, query_.timeout)
654659 async def work(tx):
655- result = await tx.run(query_, parameters_, **kwargs)
660+ result = await tx.run(query_.text , parameters_, **kwargs)
656661 return await result_transformer_(result)
657662
658663 async with driver.session(
@@ -709,16 +714,19 @@ async def example(driver: neo4j.AsyncDriver) -> int:
709714 assert isinstance(count, int)
710715 return count
711716
712- :param query_: cypher query to execute
713- :type query_: typing.LiteralString
717+ :param query_:
718+ Cypher query to execute.
719+ Use a :class:`.Query` object to pass a query with additional
720+ transaction configuration.
721+ :type query_: typing.LiteralString | Query
714722 :param parameters_: parameters to use in the query
715723 :type parameters_: typing.Optional[typing.Dict[str, typing.Any]]
716724 :param routing_:
717- whether to route the query to a reader (follower/read replica) or
725+ Whether to route the query to a reader (follower/read replica) or
718726 a writer (leader) in the cluster. Default is to route to a writer.
719727 :type routing_: RoutingControl
720728 :param database_:
721- database to execute the query against.
729+ Database to execute the query against.
722730
723731 None (default) uses the database configured on the server side.
724732
@@ -838,6 +846,10 @@ async def example(driver: neo4j.AsyncDriver) -> neo4j.Record::
838846
839847 .. versionchanged:: 5.14
840848 Stabilized ``auth_`` parameter from preview.
849+
850+ .. versionchanged:: 5.15
851+ The ``query_`` parameter now also accepts a :class:`.Query` object
852+ instead of only :class:`str`.
841853 """
842854 self ._check_state ()
843855 invalid_kwargs = [k for k in kwargs if
@@ -850,6 +862,14 @@ async def example(driver: neo4j.AsyncDriver) -> neo4j.Record::
850862 "latter case, use the `parameters_` dictionary instead."
851863 % invalid_kwargs
852864 )
865+ if isinstance (query_ , Query ):
866+ timeout = query_ .timeout
867+ metadata = query_ .metadata
868+ query_str = query_ .text
869+ work = unit_of_work (metadata , timeout )(_work )
870+ else :
871+ query_str = query_
872+ work = _work
853873 parameters = dict (parameters_ or {}, ** kwargs )
854874
855875 if bookmark_manager_ is _default :
@@ -876,7 +896,7 @@ async def example(driver: neo4j.AsyncDriver) -> neo4j.Record::
876896 with session ._pipelined_begin :
877897 return await session ._run_transaction (
878898 access_mode , TelemetryAPI .DRIVER ,
879- _work , (query_ , parameters , result_transformer_ ), {}
899+ work , (query_str , parameters , result_transformer_ ), {}
880900 )
881901
882902 @property
@@ -1195,7 +1215,7 @@ async def _get_server_info(self, session_config) -> ServerInfo:
11951215
11961216async def _work (
11971217 tx : AsyncManagedTransaction ,
1198- query : str ,
1218+ query : te . LiteralString ,
11991219 parameters : t .Dict [str , t .Any ],
12001220 transformer : t .Callable [[AsyncResult ], t .Awaitable [_T ]]
12011221) -> _T :
0 commit comments