StoredProcedure class
按 ID 读取、替换、删除或执行特定现有存储过程的作。
若要执行创建、读取所有或查询存储过程的作,
方法
delete(Request |
删除给定的 StoredProcedure。 示例
|
execute<T>(Partition |
执行给定的 StoredProcedure。 客户端不强制执行指定的类型 T。 请务必验证来自存储过程的响应是否与你提供的类型 T 匹配。 示例
|
read(Request |
读取给定 StoredProcedure的 StoredProcedureDefinition。 示例
|
replace(Stored |
将给定的 StoredProcedure 替换为指定的 StoredProcedureDefinition。 示例
|
属性详细信息
container
id
id: string
属性值
string
url
返回资源的引用 URL。 用于在权限中链接。
string url
属性值
string
方法详细信息
delete(RequestOptions)
删除给定的 StoredProcedure。
示例
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>
参数
- options
- RequestOptions
返回
Promise<StoredProcedureResponse>
execute<T>(PartitionKey, any[], RequestOptions)
执行给定的 StoredProcedure。
客户端不强制执行指定的类型 T。 请务必验证来自存储过程的响应是否与你提供的类型 T 匹配。
示例
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>>
参数
- partitionKey
- PartitionKey
执行存储过程时要使用的分区键
- params
-
any[]
要作为参数传递给给定 StoredProcedure的参数数组。
- options
- RequestOptions
其他选项,例如要调用 StoredProcedure 的分区键。 *
返回
Promise<ResourceResponse<T>>
read(RequestOptions)
读取给定 StoredProcedure的 StoredProcedureDefinition。
示例
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>
参数
- options
- RequestOptions
返回
Promise<StoredProcedureResponse>
replace(StoredProcedureDefinition, RequestOptions)
将给定的 StoredProcedure 替换为指定的 StoredProcedureDefinition。
示例
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>
参数
指定的 StoredProcedureDefinition 替换现有定义。
- options
- RequestOptions
返回
Promise<StoredProcedureResponse>