Skip to content

Commit 1b74aa6

Browse files
authored
Merge pull request #19 from RedisGraph/readme-update
Longer explanation of QueryResult and Record interaction
2 parents a2bd290 + 6f5bc74 commit 1b74aa6

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

README.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ $ go get github.com/redislabs/redisgraph-go
2121

2222
## Usage
2323

24+
The complete `redisgraph-go` API is documented on [GoDoc](https://godoc.org/github.com/RedisGraph/redisgraph-go).
25+
2426
```go
2527
package main
2628

@@ -66,33 +68,41 @@ func main() {
6668

6769
query := `MATCH (p:person)-[v:visited]->(c:country)
6870
RETURN p.name, p.age, c.name`
69-
rs, _ := graph.Query(query)
7071

71-
rs.PrettyPrint()
72+
// result is a QueryResult struct containing the query's generated records and statistics.
73+
result, _ := graph.Query(query)
74+
75+
// Pretty-print the full result set as a table.
76+
result.PrettyPrint()
7277

73-
// Access individual result record.
74-
// As long as there are records to consume.
75-
for rs.Next() {
76-
// Get current record.
77-
r := rs.Record()
78+
// Iterate over each individual Record in the result.
79+
for result.Next() { // Next returns true until the iterator is depleted.
80+
// Get the current Record.
81+
r := result.Record()
7882

79-
p_name := r.GetByIndex(0).(string)
80-
p_age := r.GetByIndex(1).(int)
81-
c_name := r.GetByIndex(2).(string)
82-
fmt.Printf("p_name: %s p_age: %d c_name: %s\n", p_name, p_age, c_name)
83+
// Entries in the Record can be accessed by index or key.
84+
p_name := r.GetByIndex(0)
85+
fmt.Printf("\nName: %s\n", p_name)
86+
p_age, _ := r.Get("p.age")
87+
fmt.Printf("\nAge: %d\n", p_age)
8388
}
8489
}
8590
```
8691

87-
Running the above should output:
92+
Running the above produces the output:
8893

8994
```sh
90-
$ go run main.go
91-
+----------+-----------+--------+
92-
| p.name | p.age | c.name |
93-
+----------+-----------+--------+
94-
| John Doe | 33.000000 | Japan |
95-
+----------+-----------+--------+
95+
+----------+-------+--------+
96+
| p.name | p.age | c.name |
97+
+----------+-------+--------+
98+
| John Doe | 33 | Japan |
99+
+----------+-------+--------+
100+
101+
Query internal execution time 1.623063
102+
103+
Name: John Doe
104+
105+
Age: 33
96106
```
97107

98108
## Running tests

0 commit comments

Comments
 (0)