Freigeben über


StoredProcedure class

Vorgänge zum Lesen, Ersetzen, Löschen oder Ausführen einer bestimmten, vorhandenen gespeicherten Prozedur nach ID.

Für Vorgänge zum Erstellen, Lesen aller oder Abfragen gespeicherter Prozeduren,

Eigenschaften

container
id
url

Gibt eine Verweis-URL für die Ressource zurück. Wird zum Verknüpfen in Berechtigungen verwendet.

Methoden

delete(RequestOptions)

Löschen Sie die angegebene StoredProcedure.

Beispiel

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)

Führen Sie den angegebenen StoredProcedureaus.

Der angegebene Typ T wird vom Client nicht erzwungen. Stellen Sie sicher, dass die Antwort der gespeicherten Prozedur mit dem Typ T übereinstimmt, den Sie angeben.

Beispiel

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)

Lesen Sie die StoredProcedureDefinition- für den angegebenen StoredProcedure-.

Beispiel

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)

Ersetzen Sie die angegebene StoredProcedure- durch die angegebene StoredProcedureDefinition.

Beispiel

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

Details zur Eigenschaft

container

container: Container

Eigenschaftswert

id

id: string

Eigenschaftswert

string

url

Gibt eine Verweis-URL für die Ressource zurück. Wird zum Verknüpfen in Berechtigungen verwendet.

string url

Eigenschaftswert

string

Details zur Methode

delete(RequestOptions)

Löschen Sie die angegebene StoredProcedure.

Beispiel

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>

Parameter

options
RequestOptions

Gibt zurück

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

Führen Sie den angegebenen StoredProcedureaus.

Der angegebene Typ T wird vom Client nicht erzwungen. Stellen Sie sicher, dass die Antwort der gespeicherten Prozedur mit dem Typ T übereinstimmt, den Sie angeben.

Beispiel

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

Parameter

partitionKey
PartitionKey

Der Partitionsschlüssel, der beim Ausführen der gespeicherten Prozedur verwendet werden soll

params

any[]

Array von Parametern, die als Argumente an die angegebene StoredProcedureübergeben werden sollen.

options
RequestOptions

Weitere Optionen, z. B. der Partitionsschlüssel, um die StoredProcedure- aufzurufen. *

Gibt zurück

Promise<ResourceResponse<T>>

read(RequestOptions)

Lesen Sie die StoredProcedureDefinition- für den angegebenen StoredProcedure-.

Beispiel

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>

Parameter

options
RequestOptions

Gibt zurück

replace(StoredProcedureDefinition, RequestOptions)

Ersetzen Sie die angegebene StoredProcedure- durch die angegebene StoredProcedureDefinition.

Beispiel

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>

Parameter

body
StoredProcedureDefinition

Die angegebene StoredProcedureDefinition, um die vorhandene Definition zu ersetzen.

options
RequestOptions

Gibt zurück