@@ -7,7 +7,7 @@ _Cursor_ instances are incrementally depleted as they are read from.
77
88``` js
99const 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` );
1111// query result list: [1, 2, 3, 4, 5]
1212const value = await cursor .next ();
1313assert .equal (value, 1 );
@@ -31,8 +31,8 @@ remaining result list.
3131** Examples**
3232
3333``` 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 ();
3636// result is an array containing the entire query result
3737assert .deepEqual (result, [1 , 2 , 3 , 4 , 5 ]);
3838assert .equal (cursor .hasNext (), false );
@@ -86,22 +86,22 @@ Equivalent to _Array.prototype.forEach_ (except async).
8686
8787** Arguments**
8888
89- * ** fn** : ` Function `
89+ - ** fn** : ` Function `
9090
9191 A function that will be invoked for each value in the cursor's remaining
9292 result list until it explicitly returns ` false ` or the cursor is exhausted.
9393
9494 The function receives the following arguments:
9595
96- * ** value** : ` any `
96+ - ** value** : ` any `
9797
9898 The value in the cursor's remaining result list.
9999
100- * ** index** : ` number `
100+ - ** index** : ` number `
101101
102102 The index of the value in the cursor's remaining result list.
103103
104- * ** cursor** : ` Cursor `
104+ - ** cursor** : ` Cursor `
105105
106106 The cursor itself.
107107
@@ -115,11 +115,11 @@ function doStuff(value) {
115115 return VALUE ;
116116}
117117
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` );
119119const last = await cursor .each (doStuff);
120- assert .deepEqual (results, [' A ' , ' B ' , ' C ' ]);
120+ assert .deepEqual (results, [" A " , " B " , " C " ]);
121121assert .equal (cursor .hasNext (), false );
122- assert .equal (last, ' C ' );
122+ assert .equal (last, " C " );
123123```
124124
125125## cursor.every
@@ -137,30 +137,30 @@ Equivalent to _Array.prototype.every_ (except async).
137137
138138** Arguments**
139139
140- * ** fn** : ` Function `
140+ - ** fn** : ` Function `
141141
142142 A function that will be invoked for each value in the cursor's remaining
143143 result list until it returns a value that evaluates to ` false ` or the cursor
144144 is exhausted.
145145
146146 The function receives the following arguments:
147147
148- * ** value** : ` any `
148+ - ** value** : ` any `
149149
150150 The value in the cursor's remaining result list.
151151
152- * ** index** : ` number `
152+ - ** index** : ` number `
153153
154154 The index of the value in the cursor's remaining result list.
155155
156- * ** cursor** : ` Cursor `
156+ - ** cursor** : ` Cursor `
157157
158158 The cursor itself.
159159
160160``` js
161161const even = value => value % 2 === 0 ;
162162
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` );
164164const result = await cursor .every (even);
165165assert .equal (result, false ); // 3 is not even
166166assert .equal (cursor .hasNext (), true );
@@ -187,7 +187,7 @@ Equivalent to _Array.prototype.some_ (except async).
187187``` js
188188const even = value => value % 2 === 0 ;
189189
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` );
191191const result = await cursor .some (even);
192192assert .equal (result, true ); // 2 is even
193193assert .equal (cursor .hasNext (), true );
@@ -198,7 +198,7 @@ assert.equal(value, 3); // next value after 2
198198
199199## cursor.map
200200
201- ` cursor.map(fn): Array<any> `
201+ ` async cursor.map(fn): Array<any>`
202202
203203Advances the cursor by applying the function _ fn_ to each value in the cursor's
204204remaining result list until the cursor is exhausted.
@@ -212,30 +212,30 @@ to do this for very large query result sets.
212212
213213** Arguments**
214214
215- * ** fn** : ` Function `
215+ - ** fn** : ` Function `
216216
217217 A function that will be invoked for each value in the cursor's remaining
218218 result list until the cursor is exhausted.
219219
220220 The function receives the following arguments:
221221
222- * ** value** : ` any `
222+ - ** value** : ` any `
223223
224224 The value in the cursor's remaining result list.
225225
226- * ** index** : ` number `
226+ - ** index** : ` number `
227227
228228 The index of the value in the cursor's remaining result list.
229229
230- * ** cursor** : ` Cursor `
230+ - ** cursor** : ` Cursor `
231231
232232 The cursor itself.
233233
234234** Examples**
235235
236236``` js
237237const 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` );
239239const result = await cursor .map (square);
240240assert .equal (result .length , 5 );
241241assert .deepEqual (result, [1 , 4 , 9 , 16 , 25 ]);
@@ -244,7 +244,7 @@ assert.equal(cursor.hasNext(), false);
244244
245245## cursor.reduce
246246
247- ` cursor.reduce(fn, [accu]): any `
247+ ` async cursor.reduce(fn, [accu]): any`
248248
249249Exhausts the cursor by reducing the values in the cursor's remaining result list
250250with 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).
255255
256256** Arguments**
257257
258- * ** fn** : ` Function `
258+ - ** fn** : ` Function `
259259
260260 A function that will be invoked for each value in the cursor's remaining
261261 result list until the cursor is exhausted.
262262
263263 The function receives the following arguments:
264264
265- * ** accu** : ` any `
265+ - ** accu** : ` any `
266266
267267 The return value of the previous call to _ fn_ . If this is the first call,
268268 _ accu_ will be set to the _ accu_ value passed to _ reduce_ or the first value
269269 in the cursor's remaining result list.
270270
271- * ** value** : ` any `
271+ - ** value** : ` any `
272272
273273 The value in the cursor's remaining result list.
274274
275- * ** index** : ` number `
275+ - ** index** : ` number `
276276
277277 The index of the value in the cursor's remaining result list.
278278
279- * ** cursor** : ` Cursor `
279+ - ** cursor** : ` Cursor `
280280
281281 The cursor itself.
282282
@@ -286,8 +286,8 @@ Equivalent to _Array.prototype.reduce_ (except async).
286286const add = (a , b ) => a + b;
287287const baseline = 1000 ;
288288
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);
291291assert .equal (result, baseline + 1 + 2 + 3 + 4 + 5 );
292292assert .equal (cursor .hasNext (), false );
293293
@@ -297,3 +297,21 @@ const result = await cursor.reduce(add);
297297assert .equal (result, 1 + 2 + 3 + 4 + 5 );
298298assert .equal (cursor .hasNext (), false );
299299```
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