1616use Psr \Http \Client \RequestExceptionInterface ;
1717use RuntimeException ;
1818use stdClass ;
19+ use Neo4j \QueryAPI \Objects \Bookmarks ;
1920
20- /**
21- * @method parseChildren(mixed $children)
22- */
2321class Neo4jQueryAPI
2422{
23+
2524 private Client $ client ;
2625
2726 public function __construct (Client $ client )
@@ -48,26 +47,26 @@ public static function login(string $address, string $username, string $password
4847 * @throws Neo4jException
4948 * @throws RequestExceptionInterface
5049 */
51- public function run (string $ cypher , array $ parameters = [], string $ database = 'neo4j ' ): ResultSet
50+ public function run (string $ cypher , array $ parameters = [], string $ database = 'neo4j ' , Bookmarks $ bookmark = null ): ResultSet
5251 {
5352 try {
54- // Prepare the payload for the request
5553 $ payload = [
5654 'statement ' => $ cypher ,
5755 'parameters ' => empty ($ parameters ) ? new stdClass () : $ parameters ,
58- 'includeCounters ' => true
56+ 'includeCounters ' => true ,
5957 ];
6058
61- // Execute the request to the Neo4j server
59+ if ($ bookmark !== null ) {
60+ $ payload ['bookmarks ' ] = $ bookmark ->getBookmarks ();
61+ }
62+
6263 $ response = $ this ->client ->post ('/db/ ' . $ database . '/query/v2 ' , [
6364 'json ' => $ payload ,
6465 ]);
6566
66- // Decode the response body
6767 $ data = json_decode ($ response ->getBody ()->getContents (), true );
6868 $ ogm = new OGM ();
6969
70- // Extract result rows
7170 $ keys = $ data ['data ' ]['fields ' ];
7271 $ values = $ data ['data ' ]['values ' ];
7372 $ rows = array_map (function ($ resultRow ) use ($ ogm , $ keys ) {
@@ -79,31 +78,31 @@ public function run(string $cypher, array $parameters = [], string $database = '
7978 return new ResultRow ($ data );
8079 }, $ values );
8180
82-
8381 if (isset ($ data ['profiledQueryPlan ' ])) {
8482 $ profile = $ this ->createProfileData ($ data ['profiledQueryPlan ' ]);
8583 }
8684
85+ $ resultCounters = new ResultCounters (
86+ containsUpdates: $ data ['counters ' ]['containsUpdates ' ] ?? false ,
87+ nodesCreated: $ data ['counters ' ]['nodesCreated ' ] ?? 0 ,
88+ nodesDeleted: $ data ['counters ' ]['nodesDeleted ' ] ?? 0 ,
89+ propertiesSet: $ data ['counters ' ]['propertiesSet ' ] ?? 0 ,
90+ relationshipsCreated: $ data ['counters ' ]['relationshipsCreated ' ] ?? 0 ,
91+ relationshipsDeleted: $ data ['counters ' ]['relationshipsDeleted ' ] ?? 0 ,
92+ labelsAdded: $ data ['counters ' ]['labelsAdded ' ] ?? 0 ,
93+ labelsRemoved: $ data ['counters ' ]['labelsRemoved ' ] ?? 0 ,
94+ indexesAdded: $ data ['counters ' ]['indexesAdded ' ] ?? 0 ,
95+ indexesRemoved: $ data ['counters ' ]['indexesRemoved ' ] ?? 0 ,
96+ constraintsAdded: $ data ['counters ' ]['constraintsAdded ' ] ?? 0 ,
97+ constraintsRemoved: $ data ['counters ' ]['constraintsRemoved ' ] ?? 0 ,
98+ containsSystemUpdates: $ data ['counters ' ]['containsSystemUpdates ' ] ?? false ,
99+ systemUpdates: $ data ['counters ' ]['systemUpdates ' ] ?? 0
100+ );
87101
88- // Return a ResultSet containing rows, counters, and the profiled query plan
89102 return new ResultSet (
90103 $ rows ,
91- new ResultCounters (
92- containsUpdates: $ data ['counters ' ]['containsUpdates ' ],
93- nodesCreated: $ data ['counters ' ]['nodesCreated ' ],
94- nodesDeleted: $ data ['counters ' ]['nodesDeleted ' ],
95- propertiesSet: $ data ['counters ' ]['propertiesSet ' ],
96- relationshipsCreated: $ data ['counters ' ]['relationshipsCreated ' ],
97- relationshipsDeleted: $ data ['counters ' ]['relationshipsDeleted ' ],
98- labelsAdded: $ data ['counters ' ]['labelsAdded ' ],
99- labelsRemoved: $ data ['counters ' ]['labelsRemoved ' ],
100- indexesAdded: $ data ['counters ' ]['indexesAdded ' ],
101- indexesRemoved: $ data ['counters ' ]['indexesRemoved ' ],
102- constraintsAdded: $ data ['counters ' ]['constraintsAdded ' ],
103- constraintsRemoved: $ data ['counters ' ]['constraintsRemoved ' ],
104- containsSystemUpdates: $ data ['counters ' ]['containsSystemUpdates ' ],
105- systemUpdates: $ data ['counters ' ]['systemUpdates ' ]
106- ),
104+ $ resultCounters ,
105+ new Bookmarks ($ data ['bookmarks ' ] ?? []),
107106 $ profile
108107 );
109108 } catch (RequestExceptionInterface $ e ) {
@@ -112,7 +111,7 @@ public function run(string $cypher, array $parameters = [], string $database = '
112111 $ contents = $ response ->getBody ()->getContents ();
113112 $ errorResponse = json_decode ($ contents , true );
114113
115- throw Neo4jException::fromNeo4jResponse ($ errorResponse , $ e );
114+ throw Neo4jException::fromNeo4jResponse ($ errorResponse , $ e );
116115 }
117116
118117 throw $ e ;
0 commit comments