Skip to content

Commit 780af86

Browse files
committed
[DE-509] Add allowRetry query option support
1 parent 9b75dc8 commit 780af86

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ This driver uses semantic versioning:
5151

5252
This option was added in ArangoDB 3.11.
5353

54+
- Added support for `allowRetry` option in `db.query`
55+
56+
This feature was added in ArangoDB 3.11.
57+
5458
- Added `x-arango-driver` header
5559

5660
The arangojs driver now correctly identifies itself to ArangoDB, allowing the

src/cursor.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export class BatchedArrayCursor<T = any> {
158158
protected _count?: number;
159159
protected _extra: CursorExtras;
160160
protected _hasMore: boolean;
161+
protected _nextBatchId?: string;
161162
protected _id: string | undefined;
162163
protected _hostUrl?: string;
163164
protected _allowDirtyRead?: boolean;
@@ -172,6 +173,7 @@ export class BatchedArrayCursor<T = any> {
172173
extra: any;
173174
result: T[];
174175
hasMore: boolean;
176+
nextBatchId?: string;
175177
id: string;
176178
count: number;
177179
},
@@ -185,6 +187,7 @@ export class BatchedArrayCursor<T = any> {
185187
this._batches = batches;
186188
this._id = body.id;
187189
this._hasMore = Boolean(body.id && body.hasMore);
190+
this._nextBatchId = body.nextBatchId;
188191
this._hostUrl = hostUrl;
189192
this._count = body.count;
190193
this._extra = body.extra;
@@ -209,15 +212,25 @@ export class BatchedArrayCursor<T = any> {
209212
}
210213

211214
protected async _more(): Promise<void> {
212-
if (!this.hasMore) return;
215+
if (!this._id || !this.hasMore) return;
213216
const body = await this._db.request({
214-
method: "PUT",
215-
path: `/_api/cursor/${encodeURIComponent(this._id!)}`,
217+
...(this._nextBatchId
218+
? {
219+
method: "POST",
220+
path: `/_api/cursor/${encodeURIComponent(this._id)}/${
221+
this._nextBatchId
222+
}`,
223+
}
224+
: {
225+
method: "PUT",
226+
path: `/_api/cursor/${encodeURIComponent(this._id)}`,
227+
}),
216228
hostUrl: this._hostUrl,
217229
allowDirtyRead: this._allowDirtyRead,
218230
});
219231
this._batches.push(new LinkedList(body.result));
220232
this._hasMore = body.hasMore;
233+
this._nextBatchId = body.nextBatchId;
221234
}
222235

223236
/**

src/database.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ export type QueryOptions = {
189189
* Default: `false`
190190
*/
191191
allowDirtyRead?: boolean;
192+
/**
193+
* If set to `true`, cursor results will be stored by ArangoDB in such a way
194+
* that batch reads can be retried in the case of a communication error.
195+
*
196+
* Default: `false`
197+
*/
198+
allowRetry?: boolean;
192199
/**
193200
* Maximum time in milliseconds arangojs will wait for a server response.
194201
* Exceeding this value will result in the request being cancelled.

0 commit comments

Comments
 (0)