StoredProcedure class
Operations for reading, replacing, deleting, or executing a specific, existing stored procedure by id.
For operations to create, read all, or query Stored Procedures,
Properties
| container | |
| id | |
| url | Returns a reference URL to the resource. Used for linking in Permissions. |
Methods
| delete(Request |
Delete the given StoredProcedure. Example
|
| execute |
Execute the given StoredProcedure. The specified type, T, is not enforced by the client. Be sure to validate the response from the stored procedure matches the type, T, you provide. Example
|
| read(Request |
Read the StoredProcedureDefinition for the given StoredProcedure. Example
|
| replace(Stored |
Replace the given StoredProcedure with the specified StoredProcedureDefinition. Example
|
Property Details
container
id
id: string
Property Value
string
url
Returns a reference URL to the resource. Used for linking in Permissions.
string url
Property Value
string
Method Details
delete(RequestOptions)
Delete the given StoredProcedure.
Example
import { CosmosClient } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "";
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("").delete();
function delete(options?: RequestOptions): Promise
Parameters
- options
- RequestOptions
Returns
Promise<StoredProcedureResponse>
execute(PartitionKey, any[], RequestOptions)
Execute the given StoredProcedure.
The specified type, T, is not enforced by the client. Be sure to validate the response from the stored procedure matches the type, T, you provide.
Example
import { CosmosClient } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "";
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("")
.execute(undefined);
function execute(partitionKey: PartitionKey, params?: any[], options?: RequestOptions): Promise>
Parameters
- partitionKey
- PartitionKey
The partition key to use when executing the stored procedure
- params
-
any[]
Array of parameters to pass as arguments to the given StoredProcedure.
- options
- RequestOptions
Additional options, such as the partition key to invoke the StoredProcedure on. *
Returns
Promise<ResourceResponse
read(RequestOptions)
Read the StoredProcedureDefinition for the given StoredProcedure.
Example
import { CosmosClient } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "";
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("").read();
function read(options?: RequestOptions): Promise
Parameters
- options
- RequestOptions
Returns
Promise<StoredProcedureResponse>
replace(StoredProcedureDefinition, RequestOptions)
Replace the given StoredProcedure with the specified StoredProcedureDefinition.
Example
import { CosmosClient, StoredProcedureDefinition } from "@azure/cosmos";
const endpoint = "https://your-account.documents.azure.com";
const key = "";
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
Parameters
The specified StoredProcedureDefinition to replace the existing definition.
- options
- RequestOptions
Returns
Promise<StoredProcedureResponse>