Module neug.query_result
The Neug result module.
QueryResult Objects
class QueryResultQueryResult represents the result of a cypher query. It supports the JavaScript iterator protocol (for...of),
and provides methods to iterate over the results.
It has the following methods to iterate over the results:
- hasNext(): Returns true if there are more results to iterate over.
- getNext(): Returns the next result as an array.
- getAt(index): Returns the result at the specified index.
- length(): Returns the total number of results.
- columnNames(): Returns the projected column names as strings.
const { Database } = require('neug');
const db = new Database({ databasePath: '/tmp/test.db', mode: 'r' });
const conn = db.connect();
const result = conn.execute('MATCH (n) RETURN n');
for (const row of result) {
console.log(row);
}
constructor
constructor(nativeResult)Initialize the QueryResult.
- Parameters:
nativeResult(object) The result of the query, returned by the query engine. It is a C++ object and is exported to Node.js via the native binding.
hasNext
hasNext() -> booleanCheck if there are more results available.
- Returns:
- boolean True if there are more results, False otherwise.
getNext
getNext() -> ArrayGet the next row of results.
- Returns:
- Array The next row as an array of values.
getAt
getAt(index) -> ArrayGet the result at the specified index.
-
Parameters:
index(number) The index of the result to retrieve. Supports negative indexing (e.g.,-1for the last row).
-
Returns:
- Array The row at the specified index.
-
Throws:
- RangeError If the index is out of range (after resolving negative indices).
length
length() -> numberGet the total number of results.
- Returns:
- number The number of results.
columnNames
columnNames() -> string[]Return the projected column names as an array of strings.
statusCode
statusCode() -> numberGet the status code of the query result.
- Returns:
- number 0 for success, non-zero for error.
statusMessage
statusMessage() -> stringGet the status message of the query result.
- Returns:
- string The status message.
getBoltResponse
getBoltResponse() -> stringGet the result in Bolt response format.
- Returns:
- string The result in Bolt response format.
close
close()Close the query result and release resources.
[Symbol.iterator]
[Symbol.iterator]() -> IteratorMakes QueryResult iterable with for...of loops. Each iteration yields a row as an array of values.
const result = conn.execute('MATCH (p:Person) RETURN p.name, p.age');
for (const row of result) {
console.log(`${row[0]}: ${row[1]}`);
}- Yields:
- Array Each row as an array of column values.