Aracılığıyla paylaş


StoredProcedure class

Kimliğe göre belirli bir saklı yordamı okuma, değiştirme, silme veya yürütme işlemleri.

Saklı Yordamları oluşturma, okuma veya sorgulama işlemleri için,

Özellikler

container
id
url

Kaynağa bir başvuru URL'si döndürür. İzinler'de bağlantı için kullanılır.

Yöntemler

delete(RequestOptions)

Verilen StoredProceduresilin.

Örnek

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)

Verilen StoredProcedureyürütür.

Belirtilen T türü istemci tarafından zorlanmaz. Saklı yordamdan gelen yanıtı, sağladığınız T türüyle eşleştiğinden emin olun.

Örnek

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)

Verilen StoredProcedureiçin StoredProcedureDefinition okuyun.

Örnek

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)

Verilen StoredProcedure belirtilen StoredProcedureDefinitionile değiştirin.

Örnek

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

Özellik Ayrıntıları

container

container: Container

Özellik Değeri

id

id: string

Özellik Değeri

string

url

Kaynağa bir başvuru URL'si döndürür. İzinler'de bağlantı için kullanılır.

string url

Özellik Değeri

string

Yöntem Ayrıntıları

delete(RequestOptions)

Verilen StoredProceduresilin.

Örnek

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>

Parametreler

options
RequestOptions

Döndürülenler

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

Verilen StoredProcedureyürütür.

Belirtilen T türü istemci tarafından zorlanmaz. Saklı yordamdan gelen yanıtı, sağladığınız T türüyle eşleştiğinden emin olun.

Örnek

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

Parametreler

partitionKey
PartitionKey

Saklı yordamı yürütürken kullanılacak bölüm anahtarı

params

any[]

Verilen StoredProcedurebağımsız değişken olarak geçirecek parametre dizisi.

options
RequestOptions

StoredProcedure çağırmak için bölüm anahtarı gibi ek seçenekler. *

Döndürülenler

Promise<ResourceResponse<T>>

read(RequestOptions)

Verilen StoredProcedureiçin StoredProcedureDefinition okuyun.

Örnek

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>

Parametreler

options
RequestOptions

Döndürülenler

replace(StoredProcedureDefinition, RequestOptions)

Verilen StoredProcedure belirtilen StoredProcedureDefinitionile değiştirin.

Örnek

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>

Parametreler

options
RequestOptions

Döndürülenler