@@ -24,7 +24,10 @@ import (
24
24
"fmt"
25
25
)
26
26
27
- // SingleTWithContext is like SingleT. It accepts a context.Context parameter
27
+ // SingleTWithContext maps the single record left to an instance of T with the provided mapper function.
28
+ // It relies on ResultWithContext.Single and propagate its error, if any.
29
+ // It accepts a context.Context, which may be canceled or carry a deadline, to control the overall record fetching
30
+ // execution time.
28
31
func SingleTWithContext [T any ](ctx context.Context , result ResultWithContext , mapper func (* Record ) (T , error )) (T , error ) {
29
32
single , err := result .Single (ctx )
30
33
if err != nil {
@@ -33,7 +36,9 @@ func SingleTWithContext[T any](ctx context.Context, result ResultWithContext, ma
33
36
return mapper (single )
34
37
}
35
38
36
- // SingleT is like Single but maps the single Record with the provided mapper.
39
+ // SingleT maps the single record left to an instance of T with the provided mapper function.
40
+ // It relies on Result.Single and propagate its error, if any.
41
+ //
37
42
// Deprecated: use SingleTWithContext instead (the entry point of context-aware
38
43
// APIs is NewDriverWithContext)
39
44
func SingleT [T any ](result Result , mapper func (* Record ) (T , error )) (T , error ) {
@@ -44,7 +49,10 @@ func SingleT[T any](result Result, mapper func(*Record) (T, error)) (T, error) {
44
49
return mapper (single )
45
50
}
46
51
47
- // CollectTWithContext is like CollectT. It accepts a context.Context parameter
52
+ // CollectTWithContext maps the records to a slice of T with the provided mapper function.
53
+ // It relies on ResultWithContext.Collect and propagate its error, if any.
54
+ // It accepts a context.Context, which may be canceled or carry a deadline, to control the overall record fetching
55
+ // execution time.
48
56
func CollectTWithContext [T any ](ctx context.Context , result ResultWithContext , mapper func (* Record ) (T , error )) ([]T , error ) {
49
57
records , err := result .Collect (ctx )
50
58
if err != nil {
@@ -53,7 +61,9 @@ func CollectTWithContext[T any](ctx context.Context, result ResultWithContext, m
53
61
return mapAll (records , mapper )
54
62
}
55
63
56
- // CollectT is like Collect but maps each record with the provided mapper.
64
+ // CollectT maps the records to a slice of T with the provided mapper function.
65
+ // It relies on Result.Collect and propagate its error, if any.
66
+ //
57
67
// Deprecated: use CollectTWithContext instead (the entry point of context-aware
58
68
// APIs is NewDriverWithContext)
59
69
func CollectT [T any ](result Result , mapper func (* Record ) (T , error )) ([]T , error ) {
@@ -76,7 +86,8 @@ func Single(result Result, err error) (*Record, error) {
76
86
return result .Single ()
77
87
}
78
88
79
- // Collect behaves similarly to CollectWithContext
89
+ // Collect aggregates the records into a slice.
90
+ // It relies on Result.Collect and propagate its error, if any.
80
91
//
81
92
// records, err := neo4j.Collect(session.Run(...))
82
93
//
@@ -89,14 +100,14 @@ func Collect(result Result, err error) ([]*Record, error) {
89
100
return result .Collect ()
90
101
}
91
102
92
- // CollectWithContext loops through the result stream, collects records into a slice and returns the
93
- // resulting slice. Any error passed in or reported while navigating the result stream is
94
- // returned without any conversion.
103
+ // CollectWithContext aggregates the records into a slice.
104
+ // It relies on ResultWithContext.Collect and propagate its error, if any.
95
105
//
96
106
// result, err := session.Run(...)
97
107
// records, err := neo4j.CollectWithContext(ctx, result, err)
98
108
//
99
- // Note, you cannot write neo4j.CollectWithContext(ctx, session.Run(...)) due to Go limitations
109
+ // It accepts a context.Context, which may be canceled or carry a deadline, to control the overall record fetching
110
+ // execution time.
100
111
func CollectWithContext (ctx context.Context , result ResultWithContext , err error ) ([]* Record , error ) {
101
112
if err != nil {
102
113
return nil , err
0 commit comments