Items class

建立新專案的作業,以及讀取/查詢所有專案

請參閱 專案 以讀取、取代或刪除現有的容器;使用 .item(id)

屬性

container

方法

batch(OperationInput[], PartitionKey, RequestOptions)

在專案上執行交易式批次作業。

Batch 會根據作業的用途來取得作業類型的作業陣列。 Batch 是交易式的,如果一個作業失敗,則會復原所有作業。 選項包括:Create、Upsert、Read、Replace 和 Delete

使用範例:

// partitionKey is required as a second argument to batch, but defaults to the default partition key
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.batch(operations)
bulk(OperationInput[], BulkOptions, RequestOptions)

對專案執行大量作業。

大量採用作業的陣列,這些作業會根據作業的用途來輸入。 選項包括:Create、Upsert、Read、Replace 和 Delete

使用範例:

// 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)
changeFeed(ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

changeFeed(PartitionKey, ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

範例

從變更摘要的開頭讀取。

const iterator = items.readChangeFeed({ startFromBeginning: true });
const firstPage = await iterator.fetchNext();
const firstPageResults = firstPage.result
const secondPage = await iterator.fetchNext();
changeFeed<T>(ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

changeFeed<T>(PartitionKey, ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

create<T>(T, RequestOptions)

建立專案。

SDK 不一定強制執行任何提供的型別 T。 您可以取得更多或更少的屬性,而且其取決於您的邏輯來強制執行它。

JSON 專案沒有設定的架構。 它們可能包含任意數目的自訂屬性。

getChangeFeedIterator<T>(ChangeFeedIteratorOptions)

傳回反覆運算器,逐一查看變更的頁面。 傳回的反覆運算器可用來擷取單一分割區索引鍵、摘要範圍或整個容器的變更。

query(string | SqlQuerySpec, FeedOptions)

查詢所有專案。

範例

讀取要陣列的所有專案。

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();
query<T>(string | SqlQuerySpec, FeedOptions)

查詢所有專案。

範例

讀取要陣列的所有專案。

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();
readAll(FeedOptions)

讀取所有專案。

JSON 專案沒有設定的架構。 它們可能包含任意數目的自訂屬性。

範例

讀取要陣列的所有專案。

const {body: containerList} = await items.readAll().fetchAll();
readAll<T>(FeedOptions)

讀取所有專案。

SDK 不一定強制執行任何提供的型別 T。 您可以取得更多或更少的屬性,而且其取決於您的邏輯來強制執行它。

JSON 專案沒有設定的架構。 它們可能包含任意數目的自訂屬性。

範例

讀取要陣列的所有專案。

const {body: containerList} = await items.readAll().fetchAll();
readChangeFeed(ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

readChangeFeed(PartitionKey, ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

範例

從變更摘要的開頭讀取。

const iterator = items.readChangeFeed({ startFromBeginning: true });
const firstPage = await iterator.fetchNext();
const firstPageResults = firstPage.result
const secondPage = await iterator.fetchNext();
readChangeFeed<T>(ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

readChangeFeed<T>(PartitionKey, ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

upsert(unknown, RequestOptions)

向上插入專案。

JSON 專案沒有設定的架構。 它們可能包含任意數目的自訂屬性。

upsert<T>(T, RequestOptions)

向上插入專案。

SDK 不一定強制執行任何提供的型別 T。 您可以取得更多或更少的屬性,而且其取決於您的邏輯來強制執行它。

JSON 專案沒有設定的架構。 它們可能包含任意數目的自訂屬性。

屬性詳細資料

container

container: Container

屬性值

方法詳細資料

batch(OperationInput[], PartitionKey, RequestOptions)

在專案上執行交易式批次作業。

Batch 會根據作業的用途來取得作業類型的作業陣列。 Batch 是交易式的,如果一個作業失敗,則會復原所有作業。 選項包括:Create、Upsert、Read、Replace 和 Delete

使用範例:

// partitionKey is required as a second argument to batch, but defaults to the default partition key
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.batch(operations)
function batch(operations: OperationInput[], partitionKey?: PartitionKey, options?: RequestOptions): Promise<Response_2<OperationResponse[]>>

參數

operations

OperationInput[]

作業清單。 限制 100

partitionKey
PartitionKey
options
RequestOptions

用於修改要求

傳回

Promise<Response_2<OperationResponse[]>>

bulk(OperationInput[], BulkOptions, RequestOptions)

對專案執行大量作業。

大量採用作業的陣列,這些作業會根據作業的用途來輸入。 選項包括:Create、Upsert、Read、Replace 和 Delete

使用範例:

// 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)
function bulk(operations: OperationInput[], bulkOptions?: BulkOptions, options?: RequestOptions): Promise<BulkOperationResponse>

參數

operations

OperationInput[]

作業清單。 限制 100

bulkOptions
BulkOptions

選擇性選項物件,可修改大量行為。 傳遞 { continueOnError: true } 以在失敗時繼續執行作業。 (預設值為 false) ** 注意:這會在 4.0 版本中預設為 TRUE

options
RequestOptions

用於修改要求。

傳回

changeFeed(ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

function changeFeed(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>

參數

changeFeedOptions
ChangeFeedOptions

傳回

changeFeed(PartitionKey, ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

範例

從變更摘要的開頭讀取。

const iterator = items.readChangeFeed({ startFromBeginning: true });
const firstPage = await iterator.fetchNext();
const firstPageResults = firstPage.result
const secondPage = await iterator.fetchNext();
function changeFeed(partitionKey: PartitionKey, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>

參數

partitionKey
PartitionKey
changeFeedOptions
ChangeFeedOptions

傳回

changeFeed<T>(ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

function changeFeed<T>(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>

參數

changeFeedOptions
ChangeFeedOptions

傳回

changeFeed<T>(PartitionKey, ChangeFeedOptions)

ChangeFeedIterator建立 以逐一查看變更的頁面

function changeFeed<T>(partitionKey: PartitionKey, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>

參數

partitionKey
PartitionKey
changeFeedOptions
ChangeFeedOptions

傳回

create<T>(T, RequestOptions)

建立專案。

SDK 不一定強制執行任何提供的型別 T。 您可以取得更多或更少的屬性,而且其取決於您的邏輯來強制執行它。

JSON 專案沒有設定的架構。 它們可能包含任意數目的自訂屬性。

function create<T>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>

參數

body

T

表示專案的本文。 可以包含任意數目的使用者定義屬性。

options
RequestOptions

例如,用於修改要求 (,並指定資料分割索引鍵) 。

傳回

Promise<ItemResponse<T>>

getChangeFeedIterator<T>(ChangeFeedIteratorOptions)

傳回反覆運算器,逐一查看變更的頁面。 傳回的反覆運算器可用來擷取單一分割區索引鍵、摘要範圍或整個容器的變更。

function getChangeFeedIterator<T>(changeFeedIteratorOptions?: ChangeFeedIteratorOptions): ChangeFeedPullModelIterator<T>

參數

changeFeedIteratorOptions
ChangeFeedIteratorOptions

傳回

query(string | SqlQuerySpec, FeedOptions)

查詢所有專案。

範例

讀取要陣列的所有專案。

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();
function query(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<any>

參數

query

string | SqlQuerySpec

作業的查詢組態。 如需如何設定查詢的詳細資訊,請參閱 SqlQuerySpec

options
FeedOptions

例如,用於修改要求 (,並指定資料分割索引鍵) 。

傳回

query<T>(string | SqlQuerySpec, FeedOptions)

查詢所有專案。

範例

讀取要陣列的所有專案。

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();
function query<T>(query: string | SqlQuerySpec, options?: FeedOptions): QueryIterator<T>

參數

query

string | SqlQuerySpec

作業的查詢組態。 如需如何設定查詢的詳細資訊,請參閱 SqlQuerySpec

options
FeedOptions

例如,用於修改要求 (,並指定資料分割索引鍵) 。

傳回

readAll(FeedOptions)

讀取所有專案。

JSON 專案沒有設定的架構。 它們可能包含任意數目的自訂屬性。

範例

讀取要陣列的所有專案。

const {body: containerList} = await items.readAll().fetchAll();
function readAll(options?: FeedOptions): QueryIterator<ItemDefinition>

參數

options
FeedOptions

例如,用於修改要求 (,並指定資料分割索引鍵) 。

傳回

readAll<T>(FeedOptions)

讀取所有專案。

SDK 不一定強制執行任何提供的型別 T。 您可以取得更多或更少的屬性,而且其取決於您的邏輯來強制執行它。

JSON 專案沒有設定的架構。 它們可能包含任意數目的自訂屬性。

範例

讀取要陣列的所有專案。

const {body: containerList} = await items.readAll().fetchAll();
function readAll<T>(options?: FeedOptions): QueryIterator<T>

參數

options
FeedOptions

例如,用於修改要求 (,並指定資料分割索引鍵) 。

傳回

readChangeFeed(ChangeFeedOptions)

警告

此 API 現已淘汰。

Use changeFeed instead.

ChangeFeedIterator建立 以逐一查看變更的頁面

function readChangeFeed(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>

參數

changeFeedOptions
ChangeFeedOptions

傳回

readChangeFeed(PartitionKey, ChangeFeedOptions)

警告

此 API 現已淘汰。

Use changeFeed instead.

ChangeFeedIterator建立 以逐一查看變更的頁面

範例

從變更摘要的開頭讀取。

const iterator = items.readChangeFeed({ startFromBeginning: true });
const firstPage = await iterator.fetchNext();
const firstPageResults = firstPage.result
const secondPage = await iterator.fetchNext();
function readChangeFeed(partitionKey: PartitionKey, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>

參數

partitionKey
PartitionKey
changeFeedOptions
ChangeFeedOptions

傳回

readChangeFeed<T>(ChangeFeedOptions)

警告

此 API 現已淘汰。

Use changeFeed instead.

ChangeFeedIterator建立 以逐一查看變更的頁面

function readChangeFeed<T>(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>

參數

changeFeedOptions
ChangeFeedOptions

傳回

readChangeFeed<T>(PartitionKey, ChangeFeedOptions)

警告

此 API 現已淘汰。

Use changeFeed instead.

ChangeFeedIterator建立 以逐一查看變更的頁面

function readChangeFeed<T>(partitionKey: PartitionKey, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>

參數

partitionKey
PartitionKey
changeFeedOptions
ChangeFeedOptions

傳回

upsert(unknown, RequestOptions)

向上插入專案。

JSON 專案沒有設定的架構。 它們可能包含任意數目的自訂屬性。

function upsert(body: unknown, options?: RequestOptions): Promise<ItemResponse<ItemDefinition>>

參數

body

unknown

表示專案的本文。 可以包含任意數目的使用者定義屬性。

options
RequestOptions

例如,用於修改要求 (,並指定資料分割索引鍵) 。

傳回

upsert<T>(T, RequestOptions)

向上插入專案。

SDK 不一定強制執行任何提供的型別 T。 您可以取得更多或更少的屬性,而且其取決於您的邏輯來強制執行它。

JSON 專案沒有設定的架構。 它們可能包含任意數目的自訂屬性。

function upsert<T>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>

參數

body

T

表示專案的本文。 可以包含任意數目的使用者定義屬性。

options
RequestOptions

例如,用於修改要求 (,並指定資料分割索引鍵) 。

傳回

Promise<ItemResponse<T>>