Options
All
  • Public
  • Public/Protected
  • All
Menu

Class QueryIterator<T>

Represents a QueryIterator Object, an implmenetation of feed or query response that enables traversal and iterating over the response in the Azure Cosmos DB database service.

Type parameters

  • T

Hierarchy

  • QueryIterator

Index

Methods

current

executeNext

forEach

  • forEach(callback: function): Promise<void>
  • Calls a specified callback for each item returned from the query. Runs serially; each callback blocks the next.

    example

    Iterate over all databases

    await client.databases.readAll().forEach((db, headers, index) => {
      console.log(`Got ${db.id} from forEach`);
    })
    

    Parameters

    • callback: function

      Specified callback. First param is the result, second param (optional) is the current headers object state, third param (optional) is current index. No more callbacks will be called if one of them results false.

        • (result: T, headers?: IHeaders, index?: number): boolean | void
        • Parameters

          • result: T
          • Optional headers: IHeaders
          • Optional index: number

          Returns boolean | void

    Returns Promise<void>

    Promise - you should await or .catch the Promise in case there are any errors

getAsyncIterator

  • getAsyncIterator(): AsyncIterable<Response<T>>
  • Gets an async iterator that will yield results until completion.

    NOTE: AsyncIterators are a very new feature and you might need to use polyfils/etc. in order to use them in your code.

    If you're using TypeScript, you can use the following polyfill as long as you target ES6 or higher and are running on Node 6 or higher.

    if (!Symbol || !Symbol.asyncIterator) {
      (Symbol as any).asyncIterator = Symbol.for("Symbol.asyncIterator");
    }
    
    see

    QueryIterator.forEach for very similar functionality.

    example

    Iterate over all databases

    for await(const {result: db} in client.databases.readAll().getAsyncIterator()) {
      console.log(`Got ${db.id} from AsyncIterator`);
    }
    

    Returns AsyncIterable<Response<T>>

hasMoreResults

  • hasMoreResults(): boolean
  • deprecated

    Instead check if nextItem() or current() returns undefined.

    Determine if there are still remaining resources to processs based on the value of the continuation token or the\ elements remaining on the current batch in the QueryIterator.

    Returns boolean

    true if there is other elements to process in the QueryIterator.

nextItem

reset

  • reset(): void
  • Reset the QueryIterator to the beginning and clear all the resources inside it

    Returns void

toArray

  • Retrieve all the elements of the feed and pass them as an array to a function

    Returns Promise<Response<T[]>>

Generated using TypeDoc