Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Query<T, TCtor>

The Query is a helper for running queries in a Cosmos DB collection. It can be acquired from Partition.query or the static Model.crossPartitionQuery method.

Type parameters

  • T: { id: string }

  • TCtor: ModelConstructor<T>

Hierarchy

  • Query

Index

Properties

Methods

Properties

Readonly container

container: Container

Readonly ctor

ctor: TCtor

Methods

plan

  • plan(query: SqlQuerySpec): Promise<Response<PartitionedQueryExecutionInfo>>
  • Returns the query plan for the SQL query.

    Parameters

    • query: SqlQuerySpec

    Returns Promise<Response<PartitionedQueryExecutionInfo>>

raw

  • raw<TOut>(spec: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<TOut>
  • Executs the query. This returns the raw response and definitions. You can use the sql tagged template literal for easy querying, and you can use $self placeholder in the string to refer to the current collection.

    Type parameters

    • TOut = T

      Shape of returned data, defaults to the interface on the model

    Parameters

    • spec: string | SqlQuerySpec
    • Optional options: FeedOptions

    Returns QueryIterator<TOut>

run

  • run(spec: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<InstanceType<TCtor>>
  • Runs the query and returns its output in fulfilled models. You can use the sql tagged template literal for easy querying, and you can use $self placeholder in the string to refer to the current collection.

    const r = User.crossPartitionQuery().run(
     sql`SELECT c.* FROM $self c WHERE username = ${name}`);
    
    for await (const { resources } of r.getAsyncIterator()){
      for (const model of resources) {
        model.coolness++;
        await model.save();
      }
    }
    

    Parameters

    • spec: string | SqlQuerySpec
    • Optional options: FeedOptions

    Returns QueryIterator<InstanceType<TCtor>>

Generated using TypeDoc