Megosztás a következőn keresztül:


StoredProcedure class

Adott, meglévő tárolt eljárás azonosító szerinti olvasására, cseréjére, törlésére vagy végrehajtására szolgáló műveletek.

Tárolt eljárások létrehozásához, olvasásához vagy lekérdezéséhez

Tulajdonságok

container
id
url

Az erőforrás hivatkozási URL-címét adja vissza. Az engedélyek csatolásához használatos.

Metódusok

delete(RequestOptions)

Törölje a megadott StoredProcedure.

Példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

await container.scripts.storedProcedure("<sproc-id>").delete();
execute<T>(PartitionKey, any[], RequestOptions)

Hajtsa végre a megadott StoredProcedure.

A megadott típust (T) az ügyfél nem kényszeríti ki. Győződjön meg arról, hogy a tárolt eljárás válasza megegyezik az Ön által megadott T típussal.

Példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resource: result } = await container.scripts
  .storedProcedure("<sproc-id>")
  .execute(undefined);
read(RequestOptions)

Olvassa el a StoredProcedureDefinition az adott Tároltprocedure.

Példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resource: sproc } = await container.scripts.storedProcedure("<sproc-id>").read();
replace(StoredProcedureDefinition, RequestOptions)

Cserélje le a megadott StoredProcedure a megadott StoredProcedureDefinition.

Példa

import { CosmosClient, StoredProcedureDefinition } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const sprocDefinition: StoredProcedureDefinition = {
  id: "sample sproc",
  body: "function () { const x = 10; }",
};

const { resource: sproc } = await container.scripts.storedProcedures.create(sprocDefinition);

sproc.body = function () {
  const x = 20;
  console.log(x);
};
const { resource: replacedSproc } = await container.scripts
  .storedProcedure(sproc.id)
  .replace(sproc);

Tulajdonság adatai

container

container: Container

Tulajdonság értéke

id

id: string

Tulajdonság értéke

string

url

Az erőforrás hivatkozási URL-címét adja vissza. Az engedélyek csatolásához használatos.

string url

Tulajdonság értéke

string

Metódus adatai

delete(RequestOptions)

Törölje a megadott StoredProcedure.

Példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

await container.scripts.storedProcedure("<sproc-id>").delete();
function delete(options?: RequestOptions): Promise<StoredProcedureResponse>

Paraméterek

options
RequestOptions

Válaszok

execute<T>(PartitionKey, any[], RequestOptions)

Hajtsa végre a megadott StoredProcedure.

A megadott típust (T) az ügyfél nem kényszeríti ki. Győződjön meg arról, hogy a tárolt eljárás válasza megegyezik az Ön által megadott T típussal.

Példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resource: result } = await container.scripts
  .storedProcedure("<sproc-id>")
  .execute(undefined);
function execute<T>(partitionKey: PartitionKey, params?: any[], options?: RequestOptions): Promise<ResourceResponse<T>>

Paraméterek

partitionKey
PartitionKey

A tárolt eljárás végrehajtásakor használni kívánt partíciókulcs

params

any[]

Argumentumként továbbítandó paraméterek tömbje az adott StoredProcedure.

options
RequestOptions

További lehetőségek, például a StoredProcedure meghívásához szükséges partíciókulcs, be. *

Válaszok

Promise<ResourceResponse<T>>

read(RequestOptions)

Olvassa el a StoredProcedureDefinition az adott Tároltprocedure.

Példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resource: sproc } = await container.scripts.storedProcedure("<sproc-id>").read();
function read(options?: RequestOptions): Promise<StoredProcedureResponse>

Paraméterek

options
RequestOptions

Válaszok

replace(StoredProcedureDefinition, RequestOptions)

Cserélje le a megadott StoredProcedure a megadott StoredProcedureDefinition.

Példa

import { CosmosClient, StoredProcedureDefinition } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const sprocDefinition: StoredProcedureDefinition = {
  id: "sample sproc",
  body: "function () { const x = 10; }",
};

const { resource: sproc } = await container.scripts.storedProcedures.create(sprocDefinition);

sproc.body = function () {
  const x = 20;
  console.log(x);
};
const { resource: replacedSproc } = await container.scripts
  .storedProcedure(sproc.id)
  .replace(sproc);
function replace(body: StoredProcedureDefinition, options?: RequestOptions): Promise<StoredProcedureResponse>

Paraméterek

body
StoredProcedureDefinition

A megadott StoredProcedureDefinition a meglévő definíció helyére.

options
RequestOptions

Válaszok