Bagikan melalui


StoredProcedure class

Operasi untuk membaca, mengganti, menghapus, atau menjalankan prosedur tersimpan tertentu yang ada berdasarkan id.

Agar operasi membuat, membaca semua, atau mengkueri Prosedur Tersimpan,

Properti

container
id
url

Mengembalikan URL referensi ke sumber daya. Digunakan untuk menautkan di Izin.

Metode

delete(RequestOptions)

Hapus StoredProcedure yang diberikan .

Contoh

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)

Jalankan StoredProcedure yang diberikan .

Jenis yang ditentukan, T, tidak diberlakukan oleh klien. Pastikan untuk memvalidasi respons dari prosedur tersimpan sesuai dengan jenis, T, yang Anda berikan.

Contoh

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)

Baca StoredProcedureDefinition untuk StoredProcedure yang diberikan .

Contoh

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)

Ganti StoredProcedure yang diberikan dengan StoredProcedureDefinition yang ditentukan.

Contoh

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

Detail Properti

container

container: Container

Nilai Properti

id

id: string

Nilai Properti

string

url

Mengembalikan URL referensi ke sumber daya. Digunakan untuk menautkan di Izin.

string url

Nilai Properti

string

Detail Metode

delete(RequestOptions)

Hapus StoredProcedure yang diberikan .

Contoh

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

Mengembalikan

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

Jalankan StoredProcedure yang diberikan .

Jenis yang ditentukan, T, tidak diberlakukan oleh klien. Pastikan untuk memvalidasi respons dari prosedur tersimpan sesuai dengan jenis, T, yang Anda berikan.

Contoh

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

Kunci partisi yang akan digunakan saat menjalankan prosedur tersimpan

params

any[]

Array parameter untuk diteruskan sebagai argumen ke StoredProcedureyang diberikan.

options
RequestOptions

Opsi tambahan, seperti kunci partisi untuk memanggil StoredProcedure. *

Mengembalikan

Promise<ResourceResponse<T>>

read(RequestOptions)

Baca StoredProcedureDefinition untuk StoredProcedure yang diberikan .

Contoh

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

Mengembalikan

replace(StoredProcedureDefinition, RequestOptions)

Ganti StoredProcedure yang diberikan dengan StoredProcedureDefinition yang ditentukan.

Contoh

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

StoredProcedureDefinition yang ditentukan untuk menggantikan definisi yang ada.

options
RequestOptions

Mengembalikan