Items class

Operazioni per la creazione di nuovi elementi e la lettura/query di tutti gli elementi

Vedere Elemento per la lettura, la sostituzione o l'eliminazione di un contenitore esistente; usare .item(id).

Proprietà

container

Metodi

batch(OperationInput[], PartitionKey, RequestOptions)

Eseguire operazioni batch transazionali sugli elementi.

Batch accetta una matrice di operazioni tipizzata in base alle operazioni eseguite dall'operazione. Batch è transazionale e eseguirà il rollback di tutte le operazioni se si verifica un errore. Le scelte sono: Create, Upsert, Read, Replace e Delete

Esempio d'uso:

// 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)

Eseguire operazioni bulk sugli elementi.

Bulk accetta una matrice di operazioni tipizzata in base alle operazioni eseguite dall'operazione. Le scelte sono: Create, Upsert, Read, Replace e Delete

Esempio d'uso:

// 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)

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

changeFeed(PartitionKey, ChangeFeedOptions)

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

Esempio

Leggere dall'inizio del feed di modifiche.

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

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

changeFeed<T>(PartitionKey, ChangeFeedOptions)

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

create<T>(T, RequestOptions)

Creare un elemento.

Qualsiasi tipo fornito, T, non è necessariamente applicato dall'SDK. È possibile ottenere più o meno proprietà ed è fino alla logica per applicarla.

Non esiste uno schema impostato per gli elementi JSON. Possono contenere qualsiasi numero di proprietà personalizzate.

getChangeFeedIterator<T>(ChangeFeedIteratorOptions)

Restituisce un iteratore per scorrere le pagine delle modifiche. L'iteratore restituito può essere usato per recuperare le modifiche per una singola chiave di partizione, un intervallo di feed o un intero contenitore.

query(string | SqlQuerySpec, FeedOptions)

Esegue query su tutti gli elementi.

Esempio

Leggere tutti gli elementi nella matrice.

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)

Esegue query su tutti gli elementi.

Esempio

Leggere tutti gli elementi nella matrice.

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)

Leggere tutti gli elementi.

Non esiste uno schema impostato per gli elementi JSON. Possono contenere qualsiasi numero di proprietà personalizzate.

Esempio

Leggere tutti gli elementi nella matrice.

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

Leggere tutti gli elementi.

Qualsiasi tipo fornito, T, non è necessariamente applicato dall'SDK. È possibile ottenere più o meno proprietà ed è fino alla logica per applicarla.

Non esiste uno schema impostato per gli elementi JSON. Possono contenere qualsiasi numero di proprietà personalizzate.

Esempio

Leggere tutti gli elementi nella matrice.

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

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

readChangeFeed(PartitionKey, ChangeFeedOptions)

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

Esempio

Leggere dall'inizio del feed di modifiche.

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

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

readChangeFeed<T>(PartitionKey, ChangeFeedOptions)

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

upsert(unknown, RequestOptions)

Upsert un elemento.

Non esiste uno schema impostato per gli elementi JSON. Possono contenere qualsiasi numero di proprietà personalizzate.

upsert<T>(T, RequestOptions)

Upsert un elemento.

Qualsiasi tipo fornito, T, non è necessariamente applicato dall'SDK. È possibile ottenere più o meno proprietà ed è fino alla logica per applicarla.

Non esiste uno schema impostato per gli elementi JSON. Possono contenere qualsiasi numero di proprietà personalizzate.

Dettagli proprietà

container

container: Container

Valore della proprietà

Dettagli metodo

batch(OperationInput[], PartitionKey, RequestOptions)

Eseguire operazioni batch transazionali sugli elementi.

Batch accetta una matrice di operazioni tipizzata in base alle operazioni eseguite dall'operazione. Batch è transazionale e eseguirà il rollback di tutte le operazioni se si verifica un errore. Le scelte sono: Create, Upsert, Read, Replace e Delete

Esempio d'uso:

// 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[]>>

Parametri

operations

OperationInput[]

Elenco delle operazioni. Limite 100

partitionKey
PartitionKey
options
RequestOptions

Usato per modificare la richiesta

Restituisce

Promise<Response_2<OperationResponse[]>>

bulk(OperationInput[], BulkOptions, RequestOptions)

Eseguire operazioni bulk sugli elementi.

Bulk accetta una matrice di operazioni tipizzata in base alle operazioni eseguite dall'operazione. Le scelte sono: Create, Upsert, Read, Replace e Delete

Esempio d'uso:

// 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>

Parametri

operations

OperationInput[]

Elenco delle operazioni. Limite 100

bulkOptions
BulkOptions

Oggetto opzioni facoltative per modificare il comportamento bulk. Passare { continueOnError: true } per continuare l'esecuzione delle operazioni quando si verifica un errore. (Impostazione predefinita su false) ** NOTA: QUESTA IMPOSTAZIONE PREDEFINITA VERRÀ IMPOSTATA SU TRUE NELLA VERSIONE 4.0

options
RequestOptions

Usato per modificare la richiesta.

Restituisce

changeFeed(ChangeFeedOptions)

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

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

Parametri

changeFeedOptions
ChangeFeedOptions

Restituisce

changeFeed(PartitionKey, ChangeFeedOptions)

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

Esempio

Leggere dall'inizio del feed di modifiche.

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>

Parametri

partitionKey
PartitionKey
changeFeedOptions
ChangeFeedOptions

Restituisce

changeFeed<T>(ChangeFeedOptions)

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

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

Parametri

changeFeedOptions
ChangeFeedOptions

Restituisce

changeFeed<T>(PartitionKey, ChangeFeedOptions)

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

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

Parametri

partitionKey
PartitionKey
changeFeedOptions
ChangeFeedOptions

Restituisce

create<T>(T, RequestOptions)

Creare un elemento.

Qualsiasi tipo fornito, T, non è necessariamente applicato dall'SDK. È possibile ottenere più o meno proprietà ed è fino alla logica per applicarla.

Non esiste uno schema impostato per gli elementi JSON. Possono contenere qualsiasi numero di proprietà personalizzate.

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

Parametri

body

T

Rappresenta il corpo dell'elemento. Può contenere qualsiasi numero di proprietà definite dall'utente.

options
RequestOptions

Usato per modificare la richiesta, ad esempio specificando la chiave di partizione.

Restituisce

Promise<ItemResponse<T>>

getChangeFeedIterator<T>(ChangeFeedIteratorOptions)

Restituisce un iteratore per scorrere le pagine delle modifiche. L'iteratore restituito può essere usato per recuperare le modifiche per una singola chiave di partizione, un intervallo di feed o un intero contenitore.

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

Parametri

changeFeedIteratorOptions
ChangeFeedIteratorOptions

Restituisce

query(string | SqlQuerySpec, FeedOptions)

Esegue query su tutti gli elementi.

Esempio

Leggere tutti gli elementi nella matrice.

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>

Parametri

query

string | SqlQuerySpec

Configurazione delle query per l'operazione. Per altre informazioni su come configurare una query, vedere SqlQuerySpec .

options
FeedOptions

Usato per modificare la richiesta, ad esempio specificando la chiave di partizione.

Restituisce

query<T>(string | SqlQuerySpec, FeedOptions)

Esegue query su tutti gli elementi.

Esempio

Leggere tutti gli elementi nella matrice.

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>

Parametri

query

string | SqlQuerySpec

Configurazione delle query per l'operazione. Per altre informazioni su come configurare una query, vedere SqlQuerySpec .

options
FeedOptions

Usato per modificare la richiesta, ad esempio specificando la chiave di partizione.

Restituisce

readAll(FeedOptions)

Leggere tutti gli elementi.

Non esiste uno schema impostato per gli elementi JSON. Possono contenere qualsiasi numero di proprietà personalizzate.

Esempio

Leggere tutti gli elementi nella matrice.

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

Parametri

options
FeedOptions

Usato per modificare la richiesta, ad esempio specificando la chiave di partizione.

Restituisce

readAll<T>(FeedOptions)

Leggere tutti gli elementi.

Qualsiasi tipo fornito, T, non è necessariamente applicato dall'SDK. È possibile ottenere più o meno proprietà ed è fino alla logica per applicarla.

Non esiste uno schema impostato per gli elementi JSON. Possono contenere qualsiasi numero di proprietà personalizzate.

Esempio

Leggere tutti gli elementi nella matrice.

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

Parametri

options
FeedOptions

Usato per modificare la richiesta, ad esempio specificando la chiave di partizione.

Restituisce

readChangeFeed(ChangeFeedOptions)

Avviso

Questa API è ora deprecata.

Use changeFeed instead.

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

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

Parametri

changeFeedOptions
ChangeFeedOptions

Restituisce

readChangeFeed(PartitionKey, ChangeFeedOptions)

Avviso

Questa API è ora deprecata.

Use changeFeed instead.

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

Esempio

Leggere dall'inizio del feed di modifiche.

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>

Parametri

partitionKey
PartitionKey
changeFeedOptions
ChangeFeedOptions

Restituisce

readChangeFeed<T>(ChangeFeedOptions)

Avviso

Questa API è ora deprecata.

Use changeFeed instead.

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

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

Parametri

changeFeedOptions
ChangeFeedOptions

Restituisce

readChangeFeed<T>(PartitionKey, ChangeFeedOptions)

Avviso

Questa API è ora deprecata.

Use changeFeed instead.

Creare un ChangeFeedIterator oggetto per scorrere le pagine delle modifiche

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

Parametri

partitionKey
PartitionKey
changeFeedOptions
ChangeFeedOptions

Restituisce

upsert(unknown, RequestOptions)

Upsert un elemento.

Non esiste uno schema impostato per gli elementi JSON. Possono contenere qualsiasi numero di proprietà personalizzate.

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

Parametri

body

unknown

Rappresenta il corpo dell'elemento. Può contenere qualsiasi numero di proprietà definite dall'utente.

options
RequestOptions

Usato per modificare la richiesta, ad esempio specificando la chiave di partizione.

Restituisce

upsert<T>(T, RequestOptions)

Upsert un elemento.

Qualsiasi tipo fornito, T, non è necessariamente applicato dall'SDK. È possibile ottenere più o meno proprietà ed è fino alla logica per applicarla.

Non esiste uno schema impostato per gli elementi JSON. Possono contenere qualsiasi numero di proprietà personalizzate.

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

Parametri

body

T

Rappresenta il corpo dell'elemento. Può contenere qualsiasi numero di proprietà definite dall'utente.

options
RequestOptions

Usato per modificare la richiesta, ad esempio specificando la chiave di partizione.

Restituisce

Promise<ItemResponse<T>>