ScriptsProxy Class

An interface to interact with stored procedures.

This class should not be instantiated directly. Instead, use the scripts attribute.

Inheritance
builtins.object
ScriptsProxy

Constructor

ScriptsProxy(client_connection: CosmosClientConnection, container_link: str, is_system_key: bool)

Parameters

Name Description
client_connection
Required
container_link
Required
is_system_key
Required

Methods

create_stored_procedure

Create a new stored procedure in the container.

To replace an existing sproc, use the <xref:Container.scripts.replace_stored_procedure> method.

create_trigger

Create a trigger in the container.

To replace an existing trigger, use the <xref:ContainerProxy.scripts.replace_trigger> method.

create_user_defined_function

Create a user-defined function in the container.

To replace an existing UDF, use the <xref:ContainerProxy.scripts.replace_user_defined_function> method.

delete_stored_procedure

Delete a specified stored procedure from the container.

If the stored procedure does not already exist in the container, an exception is raised.

delete_trigger

Delete a specified trigger from the container.

If the trigger does not already exist in the container, an exception is raised.

delete_user_defined_function

Delete a specified user-defined function from the container.

If the UDF does not already exist in the container, an exception is raised.

execute_stored_procedure

Execute a specified stored procedure.

If the stored procedure does not already exist in the container, an exception is raised.

get_stored_procedure

Get the stored procedure identified by id.

get_trigger

Get a trigger identified by id.

get_user_defined_function

Get a user-defined functions identified by id.

list_stored_procedures

List all stored procedures in the container.

list_triggers

List all triggers in the container.

list_user_defined_functions

List all the user-defined functions in the container.

query_stored_procedures

Return all stored procedures matching the given query.

query_triggers

Return all triggers matching the given query.

query_user_defined_functions

Return user-defined functions matching a given query.

replace_stored_procedure

Replace a specified stored procedure in the container.

If the stored procedure does not already exist in the container, an exception is raised.

replace_trigger

Replace a specified trigger in the container.

If the trigger does not already exist in the container, an exception is raised.

replace_user_defined_function

Replace a specified user-defined function in the container.

If the UDF does not already exist in the container, an exception is raised.

create_stored_procedure

Create a new stored procedure in the container.

To replace an existing sproc, use the <xref:Container.scripts.replace_stored_procedure> method.

create_stored_procedure(body: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]

Parameters

Name Description
body
Required

A dict-like object representing the sproc to create.

Returns

Type Description

A dict representing the new stored procedure.

Exceptions

Type Description

If the given stored procedure couldn't be created.

create_trigger

Create a trigger in the container.

To replace an existing trigger, use the <xref:ContainerProxy.scripts.replace_trigger> method.

create_trigger(body: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]

Parameters

Name Description
body
Required

A dict-like object representing the trigger to create.

Returns

Type Description

A dict representing the new trigger.

Exceptions

Type Description

If the given trigger couldn't be created.

create_user_defined_function

Create a user-defined function in the container.

To replace an existing UDF, use the <xref:ContainerProxy.scripts.replace_user_defined_function> method.

create_user_defined_function(body: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]

Parameters

Name Description
body
Required

A dict-like object representing the udf to create.

Returns

Type Description

A dict representing the new user-defined function.

Exceptions

Type Description

If the user-defined function couldn't be created.

delete_stored_procedure

Delete a specified stored procedure from the container.

If the stored procedure does not already exist in the container, an exception is raised.

delete_stored_procedure(sproc: str | Mapping[str, Any], **kwargs: Any) -> None

Parameters

Name Description
sproc
Required

The ID (name) or dict representing stored procedure to be deleted.

Returns

Type Description

Exceptions

Type Description

The sproc wasn't deleted successfully.

The sproc does not exist in the container.

delete_trigger

Delete a specified trigger from the container.

If the trigger does not already exist in the container, an exception is raised.

delete_trigger(trigger: str | Mapping[str, Any], **kwargs: Any) -> None

Parameters

Name Description
trigger
Required

The ID (name) or dict representing trigger to be deleted.

Returns

Type Description

Exceptions

Type Description

The trigger wasn't deleted successfully.

The trigger does not exist in the container.

delete_user_defined_function

Delete a specified user-defined function from the container.

If the UDF does not already exist in the container, an exception is raised.

delete_user_defined_function(udf: str | Mapping[str, Any], **kwargs: Any) -> None

Parameters

Name Description
udf
Required

The ID (name) or dict representing udf to be deleted.

Returns

Type Description

Exceptions

Type Description

The udf wasn't deleted successfully.

The UDF does not exist in the container.

execute_stored_procedure

Execute a specified stored procedure.

If the stored procedure does not already exist in the container, an exception is raised.

execute_stored_procedure(sproc: str | Mapping[str, Any], partition_key: str | int | float | bool | Sequence[str | int | float | bool | None] | Type[NonePartitionKeyValue] | None = None, params: List[Dict[str, Any]] | None = None, enable_script_logging: bool | None = None, **kwargs: Any) -> Dict[str, Any]

Parameters

Name Description
sproc
Required

The ID (name) or dict representing stored procedure to be executed.

partition_key
Required

Specifies the partition key to indicate which partition the sproc should execute on.

params
Required

List of parameters to be passed to the stored procedure to be executed.

enable_script_logging
Required

Enables or disables script logging for the current request.

Returns

Type Description

Result of the executed stored procedure for the given parameters.

Exceptions

Type Description

If the stored procedure execution failed or if the stored procedure with given id does not exist in the container.

get_stored_procedure

Get the stored procedure identified by id.

get_stored_procedure(sproc: str | Mapping[str, Any], **kwargs: Any) -> Dict[str, Any]

Parameters

Name Description
sproc
Required

The ID (name) or dict representing stored procedure to retrieve.

Returns

Type Description

A dict representing the retrieved stored procedure.

Exceptions

Type Description

If the given stored procedure couldn't be retrieved.

get_trigger

Get a trigger identified by id.

get_trigger(trigger: str | Mapping[str, Any], **kwargs: Any) -> Dict[str, Any]

Parameters

Name Description
trigger
Required

The ID (name) or dict representing trigger to retrieve.

Returns

Type Description

A dict representing the retrieved trigger.

Exceptions

Type Description

If the given trigger couldn't be retrieved.

get_user_defined_function

Get a user-defined functions identified by id.

get_user_defined_function(udf: str | Mapping[str, Any], **kwargs: Any) -> Dict[str, Any]

Parameters

Name Description
udf
Required

The ID (name) or dict representing udf to retrieve.

Returns

Type Description

A dict representing the retrieved user-defined function.

Exceptions

Type Description

If the user-defined function couldn't be retrieved.

list_stored_procedures

List all stored procedures in the container.

list_stored_procedures(max_item_count: int | None = None, **kwargs: Any) -> ItemPaged[Dict[str, Any]]

Parameters

Name Description
max_item_count
Required
int

Max number of items to be returned in the enumeration operation.

Returns

Type Description

An Iterable of stored procedures (dicts).

Exceptions

Type Description

If the given stored procedure couldn't be created.

list_triggers

List all triggers in the container.

list_triggers(max_item_count: int | None = None, **kwargs: Any) -> ItemPaged[Dict[str, Any]]

Parameters

Name Description
max_item_count
Required
int

Max number of items to be returned in the enumeration operation.

Returns

Type Description

An Iterable of triggers (dicts).

Exceptions

Type Description

If the given stored procedure couldn't be created.

list_user_defined_functions

List all the user-defined functions in the container.

list_user_defined_functions(max_item_count: int | None = None, **kwargs: Any) -> ItemPaged[Dict[str, Any]]

Parameters

Name Description
max_item_count
Required
int

Max number of items to be returned in the enumeration operation.

Returns

Type Description

An Iterable of user-defined functions (dicts).

Exceptions

Type Description

If the given stored procedure couldn't be created.

query_stored_procedures

Return all stored procedures matching the given query.

query_stored_procedures(query: str, parameters: List[Dict[str, Any]] | None = None, max_item_count: int | None = None, **kwargs: Any) -> ItemPaged[Dict[str, Any]]

Parameters

Name Description
query
Required
str

The Azure Cosmos DB SQL query to execute.

parameters
Required

Optional array of parameters to the query. Ignored if no query is provided.

max_item_count
Required
int

Max number of items to be returned in the enumeration operation.

Returns

Type Description

An Iterable of stored procedures (dicts).

Exceptions

Type Description

If the given stored procedure couldn't be created.

query_triggers

Return all triggers matching the given query.

query_triggers(query: str, parameters: List[Dict[str, Any]] | None = None, max_item_count: int | None = None, **kwargs: Any) -> ItemPaged[Dict[str, Any]]

Parameters

Name Description
query
Required
str

The Azure Cosmos DB SQL query to execute.

parameters
Required

Optional array of parameters to the query. Ignored if no query is provided.

max_item_count
Required
int

Max number of items to be returned in the enumeration operation.

Returns

Type Description

An Iterable of triggers (dicts).

Exceptions

Type Description

If the given stored procedure couldn't be created.

query_user_defined_functions

Return user-defined functions matching a given query.

query_user_defined_functions(query: str, parameters: List[Dict[str, Any]] | None = None, max_item_count: int | None = None, **kwargs: Any) -> ItemPaged[Dict[str, Any]]

Parameters

Name Description
query
Required
str

The Azure Cosmos DB SQL query to execute.

parameters
Required

Optional array of parameters to the query. Ignored if no query is provided.

max_item_count
Required
int

Max number of items to be returned in the enumeration operation.

Returns

Type Description

An Iterable of user-defined functions (dicts).

Exceptions

Type Description

If the given stored procedure couldn't be created.

replace_stored_procedure

Replace a specified stored procedure in the container.

If the stored procedure does not already exist in the container, an exception is raised.

replace_stored_procedure(sproc: str | Mapping[str, Any], body: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]

Parameters

Name Description
sproc
Required

The ID (name) or dict representing stored procedure to be replaced.

body
Required

A dict-like object representing the sproc to replace.

Returns

Type Description

A dict representing the stored procedure after replace went through.

Exceptions

Type Description

If the replace operation failed or the stored procedure with given id does not exist.

replace_trigger

Replace a specified trigger in the container.

If the trigger does not already exist in the container, an exception is raised.

replace_trigger(trigger: str | Mapping[str, Any], body: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]

Parameters

Name Description
trigger
Required

The ID (name) or dict representing trigger to be replaced.

body
Required

A dict-like object representing the trigger to replace.

Returns

Type Description

A dict representing the trigger after replace went through.

Exceptions

Type Description

If the replace operation failed or the trigger with given id does not exist.

replace_user_defined_function

Replace a specified user-defined function in the container.

If the UDF does not already exist in the container, an exception is raised.

replace_user_defined_function(udf: str | Mapping[str, Any], body: Dict[str, Any], **kwargs: Any) -> Dict[str, Any]

Parameters

Name Description
udf
Required

The ID (name) or dict representing udf to be replaced.

body
Required

A dict-like object representing the udf to replace.

Returns

Type Description

A dict representing the user-defined function after replace went through.

Exceptions

Type Description

If the replace operation failed or the user-defined function with the given id does not exist.