@@ -47,6 +47,37 @@ func SingleT[T any](result Result, mapper func(*Record) (T, error)) (T, error) {
47
47
return mapper (single )
48
48
}
49
49
50
+ // SingleWithContext returns one and only one record from the result stream. Any error passed in
51
+ // or reported while navigating the result stream is returned without any conversion.
52
+ // If the result stream contains zero or more than one records error is returned.
53
+ //
54
+ // result, err := session.Run(...)
55
+ // record, err := neo4j.SingleWithContext(ctx, result, err)
56
+ //
57
+ // It accepts a context.Context, which may be canceled or carry a deadline, to control the overall record fetching
58
+ // execution time.
59
+ func SingleWithContext (ctx context.Context , result ResultWithContext , err error ) (* Record , error ) {
60
+ if err != nil {
61
+ return nil , err
62
+ }
63
+ return result .Single (ctx )
64
+ }
65
+
66
+ // Single returns one and only one record from the result stream. Any error passed in
67
+ // or reported while navigating the result stream is returned without any conversion.
68
+ // If the result stream contains zero or more than one records error is returned.
69
+ //
70
+ // record, err := neo4j.Single(session.Run(...))
71
+ //
72
+ // Deprecated: use SingleWithContext instead (the entry point of context-aware
73
+ // APIs is NewDriverWithContext)
74
+ func Single (result Result , err error ) (* Record , error ) {
75
+ if err != nil {
76
+ return nil , err
77
+ }
78
+ return result .Single ()
79
+ }
80
+
50
81
// CollectTWithContext maps the records to a slice of T with the provided mapper function.
51
82
// It relies on ResultWithContext.Collect and propagate its error, if any.
52
83
// It accepts a context.Context, which may be canceled or carry a deadline, to control the overall record fetching
@@ -72,16 +103,19 @@ func CollectT[T any](result Result, mapper func(*Record) (T, error)) ([]T, error
72
103
return mapAll (records , mapper )
73
104
}
74
105
75
- // Single returns one and only one record from the result stream. Any error passed in
76
- // or reported while navigating the result stream is returned without any conversion.
77
- // If the result stream contains zero or more than one records error is returned.
106
+ // CollectWithContext aggregates the records into a slice.
107
+ // It relies on ResultWithContext.Collect and propagate its error, if any.
78
108
//
79
- // record, err := neo4j.Single(session.Run(...))
80
- func Single (result Result , err error ) (* Record , error ) {
109
+ // result, err := session.Run(...)
110
+ // records, err := neo4j.CollectWithContext(ctx, result, err)
111
+ //
112
+ // It accepts a context.Context, which may be canceled or carry a deadline, to control the overall record fetching
113
+ // execution time.
114
+ func CollectWithContext (ctx context.Context , result ResultWithContext , err error ) ([]* Record , error ) {
81
115
if err != nil {
82
116
return nil , err
83
117
}
84
- return result .Single ( )
118
+ return result .Collect ( ctx )
85
119
}
86
120
87
121
// Collect aggregates the records into a slice.
@@ -98,21 +132,6 @@ func Collect(result Result, err error) ([]*Record, error) {
98
132
return result .Collect ()
99
133
}
100
134
101
- // CollectWithContext aggregates the records into a slice.
102
- // It relies on ResultWithContext.Collect and propagate its error, if any.
103
- //
104
- // result, err := session.Run(...)
105
- // records, err := neo4j.CollectWithContext(ctx, result, err)
106
- //
107
- // It accepts a context.Context, which may be canceled or carry a deadline, to control the overall record fetching
108
- // execution time.
109
- func CollectWithContext (ctx context.Context , result ResultWithContext , err error ) ([]* Record , error ) {
110
- if err != nil {
111
- return nil , err
112
- }
113
- return result .Collect (ctx )
114
- }
115
-
116
135
// AsRecords passes any existing error or casts from to a slice of records.
117
136
// Use in combination with Collect and transactional functions:
118
137
//
0 commit comments