2016-07-06 5 views
0

Ich verwende Tornado und pydocumentDB, um eine Speicheranwendung auf Azure auszuführen. Ich habe auch eine gespeicherte Prozedur:Möglich, gespeicherte Prozedur mit DocumentDB SDK für Python auszuführen?

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);    
     }); 
    } 

Was ich versuche jedes Mal, wenn ein neuer Benutzer die counter Eigenschaft meines benutzerkennungen Dokuments zu tun ist, erhöhen wird erzeugt und ihr Dokument der Sammlung hinzugefügt. Ist es möglich, diesen Sproc aufzurufen, den Zähler zu aktualisieren, dann das Dokument nach dem neuen Zähler abzufragen und diesen neuen Zähler dann als ID für den neuen Benutzer zu verwenden? Das documentDB-SDK auf GitHub zeigt einige Methoden wie QueryStoredProcedures(self, collection_link, query, options=None): und ReadStoredProcedures(self, collection_link, options=None):, aber nichts, was tatsächlich ausgeführt wird.

Antwort