mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-26 20:31:33 +00:00
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import { Resource, StoredProcedureDefinition } from "@azure/cosmos";
|
|
import { logConsoleError, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
|
import { client } from "../CosmosClient";
|
|
import { logError } from "../Logger";
|
|
import { sendNotificationForError } from "./sendNotificationForError";
|
|
|
|
export async function readStoredProcedures(
|
|
databaseId: string,
|
|
collectionId: string
|
|
): Promise<(StoredProcedureDefinition & Resource)[]> {
|
|
let sprocs: (StoredProcedureDefinition & Resource)[];
|
|
const clearMessage = logConsoleProgress(`Querying stored procedures for container ${collectionId}`);
|
|
try {
|
|
const response = await client()
|
|
.database(databaseId)
|
|
.container(collectionId)
|
|
.scripts.storedProcedures.readAll()
|
|
.fetchAll();
|
|
sprocs = response.resources;
|
|
} catch (error) {
|
|
logConsoleError(`Failed to query stored procedures for container ${collectionId}: ${JSON.stringify(error)}`);
|
|
logError(JSON.stringify(error), "ReadStoredProcedures", error.code);
|
|
sendNotificationForError(error);
|
|
}
|
|
clearMessage();
|
|
return sprocs;
|
|
}
|