Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.94k stars 441 forks source link

CosmosDB DocumenDB Stored Procedure Binding #1819

Open graham-sportsmgmt opened 7 years ago

graham-sportsmgmt commented 7 years ago

Please add input and output bindings for DocumentDB stored procedures.

They will be needed for more complex DocumentDB operations that can't be handled in a single query or update.

Thanks!

tohling commented 7 years ago

You may use the supported DocumentClientbinding. Kindly see example at: https://github.com/Azure/azure-webjobs-sdk-extensions#documentdb

graham-sportsmgmt commented 7 years ago

I'm sorry, but I didn't see any references to DocumentDB Stored Procedures on that page. Am I missing something, or perhaps looking in the wrong spot?

christopheranderson commented 7 years ago

@brettsam - this doesn't work with our DocDB SQL support today?

brettsam commented 7 years ago

@christopheranderson -- I don't see anything in the documentation that indicates you can write a SQL query that will execute a stored procedure. I've asked the DocDB team to verify.

@graham-sportsmgmt -- @tohling is talking about using a DocumentClient parameter in your function signature. We'll give you the client and you can use that to execute stored procedures directly using the API. You're right that there's no support for input/output bindings today, but using the client directly should allow you to build the complex interactions you want. We'll keep this open and discuss how we could design this.

graham-sportsmgmt commented 7 years ago

@brettsam thanks for the clarification.

First, let me say that I would not expect a Function to create/update/delete a Stored Procedure, only execute them. Sproc management is already available to us in the Azure Portal in the feature called "Script Explorer".

Executing the sproc is as simple as passing in zero or more parameters in a JSON array, and then receiving the text output document. This output is not constrained, and could be JSON, plain text, no text, or even XML.

For our app, we use sprocs to:

These are the two main documents detailing DocumentDB sprocs: https://www.documentdb.com/javascript/tutorial https://docs.microsoft.com/en-us/azure/cosmos-db/programming

TechWatching commented 5 years ago

Is using DocumentClient still the correct way to call a stored procedure ? Or is there a stored procedure binding planned ?

brettsam commented 5 years ago

Using DocumentClient is still the way to do this. There's no planned sproc binding, although I think it's possible.

@ealsur -- have you heard much demand for this?

graham-sportsmgmt commented 5 years ago

@brettsam - this might be a chicken and egg argument. If CosmosDB SQL was to have better support throughout Azure (and much better documentation) then adoption would probably increase by an order of magnitude.

We've been using it for a few years and are relatively happy, but I have spoken to several other developers who tried it and gave up, moving to the Mongo API to get the rich query engine or Table Storage to get the simplicity, or (bah!) migrated away from Azure altogether.