Skip to content

Commit 98cf51c

Browse files
committed
Add result error handling code example
Fixes #272
1 parent f4c05be commit 98cf51c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,22 @@ There are a few points that need to be highlighted:
120120
* The driver is thread-safe, while the session or the transaction is not thread-safe.
121121

122122
## Parsing Result Values
123+
123124
### Record Stream
124125
A cypher execution result is comprised of a stream of records followed by a result summary.
125-
The records inside the result can be accessed via `Next()`/`Record()` functions defined on `Result`. It is important to check `Err()` after `Next()` returning `false` to find out whether it is end of result stream or an error that caused the end of result consumption.
126+
The records inside the result can be accessed via `Next()`/`Record()` functions defined on `Result`. It is important to check `Err()` after `Next()` returning `false` to find out whether it is the end of the result stream or an error that caused the end of result consumption.
127+
128+
```go
129+
// Next returns false upon error
130+
for result.Next() {
131+
record := result.Record()
132+
handleRecord(record)
133+
}
134+
// Err returns the error that caused Next to return false
135+
if err = result.Err(); err != nil {
136+
handleError(err)
137+
}
138+
```
126139

127140
### Accessing Values in a Record
128141
Values in a `Record` can be accessed either by index or by alias. The return value is an `interface{}` which means you need to convert the interface to the type expected

0 commit comments

Comments
 (0)