@@ -51,23 +51,19 @@ public static function login(string $address, string $username, string $password
5151 public function run (string $ cypher , array $ parameters = [], string $ database = 'neo4j ' ): ResultSet
5252 {
5353 try {
54- // Prepare the payload for the request
5554 $ payload = [
5655 'statement ' => $ cypher ,
5756 'parameters ' => empty ($ parameters ) ? new stdClass () : $ parameters ,
5857 'includeCounters ' => true
5958 ];
6059
61- // Execute the request to the Neo4j server
6260 $ response = $ this ->client ->post ('/db/ ' . $ database . '/query/v2 ' , [
6361 'json ' => $ payload ,
6462 ]);
6563
66- // Decode the response body
6764 $ data = json_decode ($ response ->getBody ()->getContents (), true );
6865 $ ogm = new OGM ();
6966
70- // Extract result rows
7167 $ keys = $ data ['data ' ]['fields ' ];
7268 $ values = $ data ['data ' ]['values ' ];
7369 $ rows = array_map (function ($ resultRow ) use ($ ogm , $ keys ) {
@@ -79,30 +75,25 @@ public function run(string $cypher, array $parameters = [], string $database = '
7975 return new ResultRow ($ data );
8076 }, $ values );
8177
78+ $ profile = isset ($ data ['profiledQueryPlan ' ]) ? $ this ->createProfileData ($ data ['profiledQueryPlan ' ]) : null ;
8279
83- if (isset ($ data ['profiledQueryPlan ' ])) {
84- $ profile = $ this ->createProfileData ($ data ['profiledQueryPlan ' ]);
85- }
86-
87-
88- // Return a ResultSet containing rows, counters, and the profiled query plan
8980 return new ResultSet (
9081 $ rows ,
9182 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 ' ]
83+ containsUpdates: $ data ['counters ' ]['containsUpdates ' ] ?? false ,
84+ nodesCreated: $ data ['counters ' ]['nodesCreated ' ] ?? 0 ,
85+ nodesDeleted: $ data ['counters ' ]['nodesDeleted ' ] ?? 0 ,
86+ propertiesSet: $ data ['counters ' ]['propertiesSet ' ] ?? 0 ,
87+ relationshipsCreated: $ data ['counters ' ]['relationshipsCreated ' ] ?? 0 ,
88+ relationshipsDeleted: $ data ['counters ' ]['relationshipsDeleted ' ] ?? 0 ,
89+ labelsAdded: $ data ['counters ' ]['labelsAdded ' ] ?? 0 ,
90+ labelsRemoved: $ data ['counters ' ]['labelsRemoved ' ] ?? 0 ,
91+ indexesAdded: $ data ['counters ' ]['indexesAdded ' ] ?? 0 ,
92+ indexesRemoved: $ data ['counters ' ]['indexesRemoved ' ] ?? 0 ,
93+ constraintsAdded: $ data ['counters ' ]['constraintsAdded ' ] ?? 0 ,
94+ constraintsRemoved: $ data ['counters ' ]['constraintsRemoved ' ] ?? 0 ,
95+ containsSystemUpdates: $ data ['counters ' ]['containsSystemUpdates ' ] ?? false ,
96+ systemUpdates: $ data ['counters ' ]['systemUpdates ' ] ?? 0
10697 ),
10798 $ profile
10899 );
@@ -111,10 +102,8 @@ public function run(string $cypher, array $parameters = [], string $database = '
111102 if ($ response !== null ) {
112103 $ contents = $ response ->getBody ()->getContents ();
113104 $ errorResponse = json_decode ($ contents , true );
114-
115105 throw Neo4jException::fromNeo4jResponse ($ errorResponse , $ e );
116106 }
117-
118107 throw $ e ;
119108 }
120109 }
@@ -132,27 +121,36 @@ public function beginTransaction(string $database = 'neo4j'): Transaction
132121
133122 private function createProfileData (array $ data ): ProfiledQueryPlan
134123 {
124+ $ ogm = new OGM ();
125+
126+ // Map arguments using OGM
135127 $ arguments = $ data ['arguments ' ];
128+ $ mappedArguments = [];
129+ foreach ($ arguments as $ key => $ value ) {
130+ $ mappedArguments [$ key ] = $ ogm ->map ($ value );
131+ }
136132
137133 $ queryArguments = new QueryArguments (
138- $ arguments ['globalMemory ' ] ?? 0 ,
139- $ arguments ['plannerImpl ' ] ?? '' ,
140- $ arguments ['memory ' ] ?? 0 ,
141- $ arguments ['stringRepresentation ' ] ?? '' ,
142- is_string ($ arguments ['runtime ' ] ?? '' ) ? $ arguments ['runtime ' ] : json_encode ($ arguments ['runtime ' ]),
143- $ arguments ['runtimeImpl ' ] ?? '' ,
144- $ arguments ['dbHits ' ] ?? 0 ,
145- $ arguments ['batchSize ' ] ?? 0 ,
146- $ arguments ['details ' ] ?? '' ,
147- $ arguments ['plannerVersion ' ] ?? '' ,
148- $ arguments ['pipelineInfo ' ] ?? '' ,
149- $ arguments ['runtimeVersion ' ] ?? '' ,
150- $ arguments ['id ' ] ?? 0 ,
151- $ arguments ['estimatedRows ' ] ?? 0.0 ,
152- is_string ($ arguments ['planner ' ] ?? '' ) ? $ arguments ['planner ' ] : json_encode ($ arguments ['planner ' ]),
153- $ arguments ['rows ' ] ?? 0
134+ $ mappedArguments ['globalMemory ' ],
135+ $ mappedArguments ['plannerImpl ' ],
136+ $ mappedArguments ['memory ' ],
137+ $ mappedArguments ['stringRepresentation ' ],
138+ is_string ($ mappedArguments ['runtime ' ] ? $ mappedArguments ['runtime ' ] : json_encode ($ mappedArguments ['runtime ' ])),
139+ $ mappedArguments ['time ' ],
140+ $ mappedArguments ['runtimeImpl ' ],
141+ $ mappedArguments ['dbHits ' ],
142+ $ mappedArguments ['batchSize ' ],
143+ $ mappedArguments ['details ' ],
144+ $ mappedArguments ['plannerVersion ' ],
145+ $ mappedArguments ['pipelineInfo ' ],
146+ $ mappedArguments ['runtimeVersion ' ],
147+ $ mappedArguments ['id ' ],
148+ (float )($ mappedArguments ['estimatedRows ' ] ?? 0.0 ),
149+ is_string ($ mappedArguments ['planner ' ] ? $ mappedArguments ['planner ' ] : json_encode ($ mappedArguments ['planner ' ])),
150+ $ mappedArguments ['rows ' ]
154151 );
155152
153+
156154 $ profiledQueryPlan = new ProfiledQueryPlan (
157155 $ data ['dbHits ' ],
158156 $ data ['records ' ],
@@ -165,14 +163,13 @@ private function createProfileData(array $data): ProfiledQueryPlan
165163 $ queryArguments
166164 );
167165
168- foreach ($ data ['children ' ] as $ child ) {
166+ // Process children recursively
167+ foreach ($ data ['children ' ] as $ child ) {
169168 $ childQueryPlan = $ this ->createProfileData ($ child );
170-
171169 $ profiledQueryPlan ->addChild ($ childQueryPlan );
172170 }
173171
174172 return $ profiledQueryPlan ;
175173 }
176174
177-
178175}
0 commit comments