QueryResult¶
Returned by all query methods (execute, executeCypher, etc.) and Transaction.execute.
Properties¶
| Property | Type | Description |
|---|---|---|
columns | string[] | Column names from the query |
length | number | Number of rows in the result |
executionTimeMs | number \| null | Query execution time in milliseconds |
rowsScanned | number \| null | Rows the query read from storage before any filter: nodes its scans and index lookups read, edges its expands read, search hits and RDF triples |
profile | QueryProfile \| null | For a PROFILE statement, its operators as a tree: totalTimeMs and root, each operator with operator, detail, rows, calls, selfTimeMs, timeMs and children (experimental); null otherwise |
Methods¶
get()¶
Get a single row by index as a plain object with column names as keys.
Throws if index is out of range.
toArray()¶
Get all rows as an array of objects.
const rows = result.toArray();
for (const row of rows) {
console.log(row['p.name'], row['p.age']);
}
rows()¶
Get all rows as an array of arrays (no column names). The TypeScript return type is object, but the runtime value is an array of arrays.
scalar()¶
Get the first column of the first row as a single value.
Throws if the result has no rows or no columns.
nodes()¶
Get all nodes found in the result.
const result = await db.execute('MATCH (p:Person) RETURN p');
for (const node of result.nodes()) {
console.log(node.id, node.labels);
}
edges()¶
Get all edges found in the result.
Example¶
const result = await db.execute('MATCH (p:Person) RETURN p.name, p.age');
// Column names
console.log(result.columns); // ['p.name', 'p.age']
// Row count
console.log(result.length); // 3
// Single row
const first = result.get(0);
console.log(first['p.name']);
// All rows as objects
for (const row of result.toArray()) {
console.log(`${row['p.name']} is ${row['p.age']} years old`);
}
// Scalar value
const count = (await db.execute('MATCH (n) RETURN count(n)')).scalar();
// Metrics
console.log(`Query took ${result.executionTimeMs}ms`);
console.log(`Scanned ${result.rowsScanned} rows`);