-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresultset.go
64 lines (54 loc) · 1.22 KB
/
resultset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package arangomanager
import (
"context"
"fmt"
driver "github.com/arangodb/go-driver"
"github.com/fatih/structs"
)
// Resultset is a cursor for multiple rows of result.
type Resultset struct {
cursor driver.Cursor
ctx context.Context
empty bool
}
// IsEmpty checks for empty resultset.
func (r *Resultset) IsEmpty() bool {
return r.empty
}
// Scan advances resultset to the next row of data.
func (r *Resultset) Scan() bool {
if r.empty {
return r.empty
}
if r.cursor.HasMore() {
return true
}
r.cursor.Close()
return false
}
// Read read the row of data to interface i.
func (r *Resultset) Read(iface interface{}) error {
meta, err := r.cursor.ReadDocument(r.ctx, iface)
if err != nil {
return fmt.Errorf("error in reading document %s", err)
}
if !structs.IsStruct(iface) {
return nil
}
s := structs.New(iface)
if f, ok := s.FieldOk("DocumentMeta"); ok {
if f.IsEmbedded() {
if err := f.Set(meta); err != nil {
return fmt.Errorf("error in assigning DocumentMeta to the structure %s", err)
}
}
}
return nil
}
// Close closed the resultset.
func (r *Resultset) Close() error {
if err := r.cursor.Close(); err != nil {
return fmt.Errorf("error in closing cursor %s", err)
}
return nil
}