2016-07-06 2 views
0

저는 Tornado와 pydocumentDB를 사용하여 Azure에서 스토리지 응용 프로그램을 실행하고 있습니다. 또한 저장 프로 시저가 있습니다Python 용 documentDB SDK를 사용하여 저장 프로 시저를 실행할 수 있습니까?

난 할 노력하고있어하면 새 사용자가 생성 될 때마다 내 user_ids 문서의 counter 속성을 증가시키고 자신의 문서 컬렉션에 추가된다
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에는 QueryStoredProcedures(self, collection_link, query, options=None): ReadStoredProcedures(self, collection_link, options=None):과 같은 몇 가지 메소드가 있지만 실제로 실행할 것은 없습니다.

답변

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

+0

이것은 완벽하게 작동, 감사합니다! document_client는 꽤 거대합니다. 저 밑에있는 다른 방법들을 보지 못했습니다. –