1
0
Fork 0

Support iterator API in query results

This commit is contained in:
Alan Plum 2016-04-29 13:28:40 +02:00
parent 43d1130c24
commit c253026711
No known key found for this signature in database
GPG Key ID: 8ED72A9A323B6EFD
3 changed files with 30 additions and 0 deletions

View File

@ -220,6 +220,12 @@ ArangoQueryCursor.prototype.next = function () {
return result;
};
ArangoQueryCursor.prototype[Symbol.iterator] = function* () {
while (this._hasNext) {
yield this.next();
}
};
////////////////////////////////////////////////////////////////////////////////
/// @brief explicitly dispose the cursor
///

View File

@ -729,6 +729,13 @@ AQLGenerator.prototype.next = function() {
return this.cursor.next();
};
AQLGenerator.prototype[Symbol.iterator] = function* () {
this._createCursor();
for (const item of this.cursor) {
yield item;
}
};
////////////////////////////////////////////////////////////////////////////////
/// Deprecated block

View File

@ -183,6 +183,16 @@ GeneralArrayCursor.prototype.next = function() {
return undefined;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief returns an iterator for the results
////////////////////////////////////////////////////////////////////////////////
GeneralArrayCursor.prototype[Symbol.iterator] = function* () {
while (this._current < this._stop) {
yield this._documents[this._current++];
}
};
////////////////////////////////////////////////////////////////////////////////
/// @brief drops the result
////////////////////////////////////////////////////////////////////////////////
@ -393,6 +403,13 @@ SimpleQuery.prototype.next = function () {
return this._execution.next();
};
SimpleQuery.prototype[Symbol.iterator] = function* () {
this.execute();
for (const item of this._execution) {
yield item;
}
};
////////////////////////////////////////////////////////////////////////////////
/// @brief was docuBlock cursorDispose
////////////////////////////////////////////////////////////////////////////////