@@ -7,7 +7,7 @@ _Cursor_ instances are incrementally depleted as they are read from.
7
7
8
8
``` js
9
9
const db = new Database ();
10
- const cursor = await db .query (' FOR x IN 1..5 RETURN x' );
10
+ const cursor = await db .query (aql ` FOR x IN 1..5 RETURN x` );
11
11
// query result list: [1, 2, 3, 4, 5]
12
12
const value = await cursor .next ();
13
13
assert .equal (value, 1 );
@@ -31,8 +31,8 @@ remaining result list.
31
31
** Examples**
32
32
33
33
``` js
34
- const cursor = await db .query (' FOR x IN 1..5 RETURN x' );
35
- const result = await cursor .all ()
34
+ const cursor = await db .query (aql ` FOR x IN 1..5 RETURN x` );
35
+ const result = await cursor .all ();
36
36
// result is an array containing the entire query result
37
37
assert .deepEqual (result, [1 , 2 , 3 , 4 , 5 ]);
38
38
assert .equal (cursor .hasNext (), false );
@@ -86,22 +86,22 @@ Equivalent to _Array.prototype.forEach_ (except async).
86
86
87
87
** Arguments**
88
88
89
- * ** fn** : ` Function `
89
+ - ** fn** : ` Function `
90
90
91
91
A function that will be invoked for each value in the cursor's remaining
92
92
result list until it explicitly returns ` false ` or the cursor is exhausted.
93
93
94
94
The function receives the following arguments:
95
95
96
- * ** value** : ` any `
96
+ - ** value** : ` any `
97
97
98
98
The value in the cursor's remaining result list.
99
99
100
- * ** index** : ` number `
100
+ - ** index** : ` number `
101
101
102
102
The index of the value in the cursor's remaining result list.
103
103
104
- * ** cursor** : ` Cursor `
104
+ - ** cursor** : ` Cursor `
105
105
106
106
The cursor itself.
107
107
@@ -115,11 +115,11 @@ function doStuff(value) {
115
115
return VALUE ;
116
116
}
117
117
118
- const cursor = await db .query (' FOR x IN ["a", "b", "c"] RETURN x' )
118
+ const cursor = await db .query (aql ` FOR x IN ["a", "b", "c"] RETURN x` );
119
119
const last = await cursor .each (doStuff);
120
- assert .deepEqual (results, [' A ' , ' B ' , ' C ' ]);
120
+ assert .deepEqual (results, [" A " , " B " , " C " ]);
121
121
assert .equal (cursor .hasNext (), false );
122
- assert .equal (last, ' C ' );
122
+ assert .equal (last, " C " );
123
123
```
124
124
125
125
## cursor.every
@@ -137,30 +137,30 @@ Equivalent to _Array.prototype.every_ (except async).
137
137
138
138
** Arguments**
139
139
140
- * ** fn** : ` Function `
140
+ - ** fn** : ` Function `
141
141
142
142
A function that will be invoked for each value in the cursor's remaining
143
143
result list until it returns a value that evaluates to ` false ` or the cursor
144
144
is exhausted.
145
145
146
146
The function receives the following arguments:
147
147
148
- * ** value** : ` any `
148
+ - ** value** : ` any `
149
149
150
150
The value in the cursor's remaining result list.
151
151
152
- * ** index** : ` number `
152
+ - ** index** : ` number `
153
153
154
154
The index of the value in the cursor's remaining result list.
155
155
156
- * ** cursor** : ` Cursor `
156
+ - ** cursor** : ` Cursor `
157
157
158
158
The cursor itself.
159
159
160
160
``` js
161
161
const even = value => value % 2 === 0 ;
162
162
163
- const cursor = await db .query (' FOR x IN 2..5 RETURN x' );
163
+ const cursor = await db .query (aql ` FOR x IN 2..5 RETURN x` );
164
164
const result = await cursor .every (even);
165
165
assert .equal (result, false ); // 3 is not even
166
166
assert .equal (cursor .hasNext (), true );
@@ -187,7 +187,7 @@ Equivalent to _Array.prototype.some_ (except async).
187
187
``` js
188
188
const even = value => value % 2 === 0 ;
189
189
190
- const cursor = await db .query (' FOR x IN 1..5 RETURN x' );
190
+ const cursor = await db .query (aql ` FOR x IN 1..5 RETURN x` );
191
191
const result = await cursor .some (even);
192
192
assert .equal (result, true ); // 2 is even
193
193
assert .equal (cursor .hasNext (), true );
@@ -198,7 +198,7 @@ assert.equal(value, 3); // next value after 2
198
198
199
199
## cursor.map
200
200
201
- ` cursor.map(fn): Array<any> `
201
+ ` async cursor.map(fn): Array<any>`
202
202
203
203
Advances the cursor by applying the function _ fn_ to each value in the cursor's
204
204
remaining result list until the cursor is exhausted.
@@ -212,30 +212,30 @@ to do this for very large query result sets.
212
212
213
213
** Arguments**
214
214
215
- * ** fn** : ` Function `
215
+ - ** fn** : ` Function `
216
216
217
217
A function that will be invoked for each value in the cursor's remaining
218
218
result list until the cursor is exhausted.
219
219
220
220
The function receives the following arguments:
221
221
222
- * ** value** : ` any `
222
+ - ** value** : ` any `
223
223
224
224
The value in the cursor's remaining result list.
225
225
226
- * ** index** : ` number `
226
+ - ** index** : ` number `
227
227
228
228
The index of the value in the cursor's remaining result list.
229
229
230
- * ** cursor** : ` Cursor `
230
+ - ** cursor** : ` Cursor `
231
231
232
232
The cursor itself.
233
233
234
234
** Examples**
235
235
236
236
``` js
237
237
const square = value => value * value;
238
- const cursor = await db .query (' FOR x IN 1..5 RETURN x' );
238
+ const cursor = await db .query (aql ` FOR x IN 1..5 RETURN x` );
239
239
const result = await cursor .map (square);
240
240
assert .equal (result .length , 5 );
241
241
assert .deepEqual (result, [1 , 4 , 9 , 16 , 25 ]);
@@ -244,7 +244,7 @@ assert.equal(cursor.hasNext(), false);
244
244
245
245
## cursor.reduce
246
246
247
- ` cursor.reduce(fn, [accu]): any `
247
+ ` async cursor.reduce(fn, [accu]): any`
248
248
249
249
Exhausts the cursor by reducing the values in the cursor's remaining result list
250
250
with the given function _ fn_ . If _ accu_ is not provided, the first value in the
@@ -255,28 +255,28 @@ Equivalent to _Array.prototype.reduce_ (except async).
255
255
256
256
** Arguments**
257
257
258
- * ** fn** : ` Function `
258
+ - ** fn** : ` Function `
259
259
260
260
A function that will be invoked for each value in the cursor's remaining
261
261
result list until the cursor is exhausted.
262
262
263
263
The function receives the following arguments:
264
264
265
- * ** accu** : ` any `
265
+ - ** accu** : ` any `
266
266
267
267
The return value of the previous call to _ fn_ . If this is the first call,
268
268
_ accu_ will be set to the _ accu_ value passed to _ reduce_ or the first value
269
269
in the cursor's remaining result list.
270
270
271
- * ** value** : ` any `
271
+ - ** value** : ` any `
272
272
273
273
The value in the cursor's remaining result list.
274
274
275
- * ** index** : ` number `
275
+ - ** index** : ` number `
276
276
277
277
The index of the value in the cursor's remaining result list.
278
278
279
- * ** cursor** : ` Cursor `
279
+ - ** cursor** : ` Cursor `
280
280
281
281
The cursor itself.
282
282
@@ -286,8 +286,8 @@ Equivalent to _Array.prototype.reduce_ (except async).
286
286
const add = (a , b ) => a + b;
287
287
const baseline = 1000 ;
288
288
289
- const cursor = await db .query (' FOR x IN 1..5 RETURN x' );
290
- const result = await cursor .reduce (add, baseline)
289
+ const cursor = await db .query (aql ` FOR x IN 1..5 RETURN x` );
290
+ const result = await cursor .reduce (add, baseline);
291
291
assert .equal (result, baseline + 1 + 2 + 3 + 4 + 5 );
292
292
assert .equal (cursor .hasNext (), false );
293
293
@@ -297,3 +297,21 @@ const result = await cursor.reduce(add);
297
297
assert .equal (result, 1 + 2 + 3 + 4 + 5 );
298
298
assert .equal (cursor .hasNext (), false );
299
299
```
300
+
301
+ ## cursor.kill
302
+
303
+ ` async cursor.kill(): void `
304
+
305
+ Kills the cursor and frees up associated database resources.
306
+
307
+ This method has no effect if all result batches have already been fetched.
308
+
309
+ ** Examples**
310
+
311
+ ``` js
312
+ const cursor = await db .query (aql` FOR x IN 1..5 RETURN x` );
313
+ await cursor .kill (); // has no effect
314
+
315
+ const cursor2 = await db .query (aql` FOR x IN 1..5 RETURN x` , { batchSize: 2 });
316
+ await cursor2 .kill (); // this kills the cursor
317
+ ```
0 commit comments