Skip to content

Commit d76b13e

Browse files
committed
Query Profile implementation script
1 parent 6736b1f commit d76b13e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/Query_Profile.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
require __DIR__ . '/../vendor/autoload.php';
3+
4+
use GuzzleHttp\Client;
5+
6+
$neo4jUrl = 'https://6f72daa1.databases.neo4j.io/db/neo4j/query/v2';
7+
$username = 'neo4j';
8+
$password = '9lWmptqBgxBOz8NVcTJjgs3cHPyYmsy63ui6Spmw1d0';
9+
10+
$client = new Client();
11+
12+
$query = "PROFILE MATCH (n:Person) RETURN n";
13+
14+
$response = $client->post($neo4jUrl, [
15+
'auth' => [$username, $password],
16+
'json' => [
17+
'statement' => $query
18+
]
19+
]);
20+
21+
$body = $response->getBody();
22+
$data = json_decode($body, true);
23+
24+
$output = [
25+
"data" => [
26+
"fields" => [],
27+
"values" => []
28+
],
29+
"profiledQueryPlan" => [],
30+
"bookmarks" => $data['bookmarks'] ?? []
31+
];
32+
33+
if (isset($data['result']['columns']) && isset($data['result']['rows'])) {
34+
$output["data"]["fields"] = $data['result']['columns'];
35+
foreach ($data['result']['rows'] as $row) {
36+
$output["data"]["values"][] = $row;
37+
}
38+
}
39+
40+
if (isset($data['profiledQueryPlan'])) {
41+
$output["profiledQueryPlan"] = $data['profiledQueryPlan'];
42+
}
43+
44+
echo json_encode($output, JSON_PRETTY_PRINT);

0 commit comments

Comments
 (0)