Package version:

Operations for creating new items, and reading/querying all items

Item for reading, replacing, or deleting an existing container; use .item(id).

Properties

container: Container

The parent container.

Methods

  • Execute transactional batch operations on items.

    Batch takes an array of Operations which are typed based on what the operation does. Batch is transactional and will rollback all operations if one fails. The choices are: Create, Upsert, Read, Replace, and Delete

    Usage example:

    // The partitionKey is a required second argument. If it’s undefined, it defaults to the expected partition key format.
    const operations: OperationInput[] = [
    {
    operationType: "Create",
    resourceBody: { id: "doc1", name: "sample", key: "A" }
    },
    {
    operationType: "Upsert",
    resourceBody: { id: "doc2", name: "other", key: "A" }
    }
    ]

    await database.container.items.batch(operations, "A")

    Parameters

    Returns Promise<Response<OperationResponse[]>>

  • Execute bulk operations on items.

    Bulk takes an array of Operations which are typed based on what the operation does. The choices are: Create, Upsert, Read, Replace, and Delete

    Usage example:

    // partitionKey is optional at the top level if present in the resourceBody
    const operations: OperationInput[] = [
    {
    operationType: "Create",
    resourceBody: { id: "doc1", name: "sample", key: "A" }
    },
    {
    operationType: "Upsert",
    partitionKey: 'A',
    resourceBody: { id: "doc2", name: "other", key: "A" }
    }
    ]

    await database.container.items.bulk(operations)

    Parameters

    • operations: OperationInput[]

      List of operations. Limit 100

    • OptionalbulkOptions: BulkOptions

      Optional options object to modify bulk behavior. Pass { continueOnError: false } to stop executing operations when one fails. (Defaults to true)

    • Optionaloptions: RequestOptions

      Used for modifying the request.

    Returns Promise<BulkOperationResponse>

  • Create an item.

    Any provided type, T, is not necessarily enforced by the SDK. You may get more or less properties and it's up to your logic to enforce it.

    There is no set schema for JSON items. They may contain any number of custom properties.

    Type Parameters

    Parameters

    • body: T

      Represents the body of the item. Can contain any number of user defined properties.

    • options: RequestOptions = {}

      Used for modifying the request (for instance, specifying the partition key).

    Returns Promise<ItemResponse<T>>

  • Queries all items in an encrypted container.

    Parameters

    • queryBuilder: EncryptionQueryBuilder

      Query configuration for the operation. See SqlQuerySpec for more info on how to build a query on encrypted properties.

    • options: FeedOptions = {}

      Used for modifying the request (for instance, specifying the partition key).

    Returns Promise<QueryIterator<ItemDefinition>>

    const queryBuilder = new EncryptionQueryBuilder("SELECT firstname FROM Families f WHERE f.lastName = @lastName");
    queryBuilder.addStringParameter("@lastName", "Hendricks", "/lastname");
    const queryIterator = await items.getEncryptionQueryIterator<{firstName: string}>(queryBuilder);
    const {result: items} = await queryIterator.fetchAll();
  • Queries all items.

    Parameters

    • query: string | SqlQuerySpec

      Query configuration for the operation. See SqlQuerySpec for more info on how to configure a query.

    • Optionaloptions: FeedOptions

      Used for modifying the request (for instance, specifying the partition key).

    Returns QueryIterator<any>

    const querySpec: SqlQuerySpec = {
    query: "SELECT * FROM Families f WHERE f.lastName = @lastName",
    parameters: [
    {name: "@lastName", value: "Hendricks"}
    ]
    };
    const {result: items} = await items.query(querySpec).fetchAll();
  • Queries all items.

    Type Parameters

    • T

    Parameters

    • query: string | SqlQuerySpec

      Query configuration for the operation. See SqlQuerySpec for more info on how to configure a query.

    • Optionaloptions: FeedOptions

      Used for modifying the request (for instance, specifying the partition key).

    Returns QueryIterator<T>

    const querySpec: SqlQuerySpec = {
    query: "SELECT firstname FROM Families f WHERE f.lastName = @lastName",
    parameters: [
    {name: "@lastName", value: "Hendricks"}
    ]
    };
    const {result: items} = await items.query<{firstName: string}>(querySpec).fetchAll();
  • Read all items.

    There is no set schema for JSON items. They may contain any number of custom properties.

    Parameters

    • Optionaloptions: FeedOptions

      Used for modifying the request (for instance, specifying the partition key).

    Returns QueryIterator<ItemDefinition>

    const {body: containerList} = await items.readAll().fetchAll();
    
  • Read all items.

    Any provided type, T, is not necessarily enforced by the SDK. You may get more or less properties and it's up to your logic to enforce it.

    There is no set schema for JSON items. They may contain any number of custom properties.

    Type Parameters

    Parameters

    • Optionaloptions: FeedOptions

      Used for modifying the request (for instance, specifying the partition key).

    Returns QueryIterator<T>

    const {body: containerList} = await items.readAll().fetchAll();
    
  • Upsert an item.

    There is no set schema for JSON items. They may contain any number of custom properties.

    Parameters

    • body: unknown

      Represents the body of the item. Can contain any number of user defined properties.

    • Optionaloptions: RequestOptions

      Used for modifying the request (for instance, specifying the partition key).

    Returns Promise<ItemResponse<ItemDefinition>>

  • Upsert an item.

    Any provided type, T, is not necessarily enforced by the SDK. You may get more or less properties and it's up to your logic to enforce it.

    There is no set schema for JSON items. They may contain any number of custom properties.

    Type Parameters

    Parameters

    • body: T

      Represents the body of the item. Can contain any number of user defined properties.

    • Optionaloptions: RequestOptions

      Used for modifying the request (for instance, specifying the partition key).

    Returns Promise<ItemResponse<T>>