简体   繁体   中英

SqlQuerySpec object as a parameter for StoredProcedure in Azure DocumentDb

Can we pass a SqlQuerySpec object as a parameter to stored procedure in Document Db? I think this gives us flexibility to send parameterized SQL text and parameters to procedure. If this is not possible, I would like to know if it is possible to access the complete SQL from the SqlQuerySpec.

Thank you, Soma.

The server-side API takes the same JSON string as the REST and node.js APIs. The SqlQuerySpec type for the .NET SDK actually translates to this before sending it up when doing a regular query.

So, here are two ways you can compose the parameterized query from within your stored procedure.

  1. In the package of parameters that you send to your stored procedure, include a JSON string like this:

     ''' { "query": "SELECT * FROM books b WHERE (b.Author.Name = @name)", "parameters": [ {"name": "@name", "value": "Herman Melville"} ] } ''' 

You may be able to pass the string directly into a call to Collection.queryDocuments() but you may have to do JSON.parse(<your string>) before calling Collection.queryDocuments()

  1. If you know the shape of your query is going to be the same for every call to this stored procedure, then you can send each parameter for your query in as a parameter for the stored procedure. You then have to compose the filterQuery object in the JavaScript of your stored procedure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM