可以使用documentDB SDK for Python运行存储过程吗?

时间:2016-07-06 20:39:31

标签: python azure stored-procedures azure-cosmosdb

我正在使用Tornado和pydocumentDB在Azure上运行存储应用程序。我也有一个存储过程:

<html>

我想要做的是每次生成新用户并将其文档添加到集合中时,都会增加user_ids文档的function userIDSproc() { var collection = getContext().getCollection(); // Query documents and take 1st item. var isAccepted = collection.queryDocuments( collection.getSelfLink(), "SELECT * FROM root r WHERE r.id='user_ids_counter'", function (err, feed, options) { if (err) throw err; // Check the feed and if empty, set the body to 'no docs found', // else take 1st element from feed if (!feed || !feed.length) getContext().getResponse().setBody('no docs found'); else tryUpdate(feed[0]) }); if (!isAccepted) throw new Error('The query was not accepted by the server.'); function tryUpdate(document){ document.counter += 1; getContext().getResponse().setBody(document['counter']); var isAccepted = collection.replaceDocument(document._self, document, function (err, document, options) { if (err) throw err; // If we have successfully updated the document - return it in the response body. getContext().getResponse().setBody(document); }); } 属性。是否可以调用Sproc,更新计数器,然后查询新计数器的文档,然后使用新计数器作为新用户的ID? GitHub上的documentDB SDK显示了一些方法,如counterQueryStoredProcedures(self, collection_link, query, options=None): ,但没有实际执行。

1 个答案:

答案 0 :(得分:0)

对于DocumentDB Python SDK,您可以调用ExecuteStoredProcedure(self, sproc_link, params, options=None)

您可以在SDK的单元测试中找到一个简短示例:

https://github.com/Azure/azure-documentdb-python/blob/e605e7ca7b1ddd2454f1014f536a0fded9e6f234/test/crud_tests.py#L3408-L3409