ballerina-library
ballerina-library copied to clipboard
[Feature]: Include PATCH document operation to the connector
Connector Name
module/cosmosdb (Cosmos DB)
Suggested feature
The patch methods are not implemented in the connector, but are available in the CosmosDB API: https://learn.microsoft.com/en-us/rest/api/cosmos-db/patch-a-document.
The "PATCH" operation allows to make partial updates to a document by specifying only the fields you want to change, leaving the rest of the document intact. This can be useful when we have a large document and only want to modify a few fields. The "PATCH" operation is also known as the "Partial Update" operation. Implement Patch Document method to include the document patch functionality to the connector
Discord : https://discord.com/channels/957996897782616114/1137459261551689861/1137459261551689861
Related issues
No response
Hi,
I'd like to work on this issue.
My proposed solution for this is to include a new API with the following function signature.
remote isolated function patchDocument(string databaseId, string containerId, string documentId, PatchOperation[] operations, int|float|decimal|string partitionKey, PatchRequestOptions? requestOptions = ()) returns DocumentResponse|error { }
The PatchOperation
record type can be defined as follows along with an enum to limit the op
field to the patch operations supported by the CosmosDB API.
public type PatchOperation record {
OperationType op;
string path;
anydata value;
};
enum OperationType {
ADD_PATCH_OPERATION = "add",
SET_PATCH_OPERATION = "set",
REPLACE_PATCH_OPERATION = "replace",
REMOVE_PATCH_OPERATION = "remove",
INCREMENT_PATCH_OPERATION = "increment",
MOVE_PATCH_OPERATION = "move"
}
Please let me know your thoughts on this. Thanks!
Hi,
Any updates on this? 👀
Hi @ImeshBalasuriya ,
The solution seems fine with some adjustments
- As there are no requestOptions for patch operations (In the doc) we can remove this param
- There is a capability called
Conditional Patch
operation which is not covered in this solution
Can improve the solution with these and you are good to go !!
Note
- Cosmos DB connector internally uses Cosmos DB Java SDK and you may have to use that too in this implementation (Version 4.48.1)
Hi @sachinira,
Thanks for the response!
The requestOptions
optional parameter is a record of type PatchRequestOptions
which contains a string field filterPredicate
that implements the Conditional Patch feature. This is in line with the Java SDK where an overloaded patchItem()
method contains a parameter of the same name.
Given that this addresses the second adjustment mentioned as well, I hope it is okay to proceed with the implementation as is.
@ImeshBalasuriya are you still working on this issue?
Hu @keizer619,
Unfortunately, I'm a bit busy atm. If the feature is urgent, please feel free to reassign the issue. If not, I am happy to continue work on it once I am free.
Can I work on this issue?