@@ -51,23 +51,19 @@ public static function login(string $address, string $username, string $password
51
51
public function run (string $ cypher , array $ parameters = [], string $ database = 'neo4j ' ): ResultSet
52
52
{
53
53
try {
54
- // Prepare the payload for the request
55
54
$ payload = [
56
55
'statement ' => $ cypher ,
57
56
'parameters ' => empty ($ parameters ) ? new stdClass () : $ parameters ,
58
57
'includeCounters ' => true
59
58
];
60
59
61
- // Execute the request to the Neo4j server
62
60
$ response = $ this ->client ->post ('/db/ ' . $ database . '/query/v2 ' , [
63
61
'json ' => $ payload ,
64
62
]);
65
63
66
- // Decode the response body
67
64
$ data = json_decode ($ response ->getBody ()->getContents (), true );
68
65
$ ogm = new OGM ();
69
66
70
- // Extract result rows
71
67
$ keys = $ data ['data ' ]['fields ' ];
72
68
$ values = $ data ['data ' ]['values ' ];
73
69
$ rows = array_map (function ($ resultRow ) use ($ ogm , $ keys ) {
@@ -79,30 +75,25 @@ public function run(string $cypher, array $parameters = [], string $database = '
79
75
return new ResultRow ($ data );
80
76
}, $ values );
81
77
78
+ $ profile = isset ($ data ['profiledQueryPlan ' ]) ? $ this ->createProfileData ($ data ['profiledQueryPlan ' ]) : null ;
82
79
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
89
80
return new ResultSet (
90
81
$ rows ,
91
82
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
106
97
),
107
98
$ profile
108
99
);
@@ -111,10 +102,8 @@ public function run(string $cypher, array $parameters = [], string $database = '
111
102
if ($ response !== null ) {
112
103
$ contents = $ response ->getBody ()->getContents ();
113
104
$ errorResponse = json_decode ($ contents , true );
114
-
115
105
throw Neo4jException::fromNeo4jResponse ($ errorResponse , $ e );
116
106
}
117
-
118
107
throw $ e ;
119
108
}
120
109
}
@@ -132,27 +121,36 @@ public function beginTransaction(string $database = 'neo4j'): Transaction
132
121
133
122
private function createProfileData (array $ data ): ProfiledQueryPlan
134
123
{
124
+ $ ogm = new OGM ();
125
+
126
+ // Map arguments using OGM
135
127
$ arguments = $ data ['arguments ' ];
128
+ $ mappedArguments = [];
129
+ foreach ($ arguments as $ key => $ value ) {
130
+ $ mappedArguments [$ key ] = $ ogm ->map ($ value );
131
+ }
136
132
137
133
$ 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 ' ]
154
151
);
155
152
153
+
156
154
$ profiledQueryPlan = new ProfiledQueryPlan (
157
155
$ data ['dbHits ' ],
158
156
$ data ['records ' ],
@@ -165,14 +163,13 @@ private function createProfileData(array $data): ProfiledQueryPlan
165
163
$ queryArguments
166
164
);
167
165
168
- foreach ($ data ['children ' ] as $ child ) {
166
+ // Process children recursively
167
+ foreach ($ data ['children ' ] as $ child ) {
169
168
$ childQueryPlan = $ this ->createProfileData ($ child );
170
-
171
169
$ profiledQueryPlan ->addChild ($ childQueryPlan );
172
170
}
173
171
174
172
return $ profiledQueryPlan ;
175
173
}
176
174
177
-
178
175
}
0 commit comments