Skip to content

Instantly share code, notes, and snippets.

@johndowns
Created January 15, 2018 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johndowns/5e1b29d415c1f9ad9a5e6a53a6691d66 to your computer and use it in GitHub Desktop.
Save johndowns/5e1b29d415c1f9ad9a5e6a53a6691d66 to your computer and use it in GitHub Desktop.
var query: IParameterizedQuery = {
query: "SELECT VALUE udf.getCustomerId(c) FROM c WHERE c.type = \'order\' AND ARRAY_CONTAINS(c.items, { productId: @productId }, true)",
parameters: [
{ name: "@productId", value: productId }
]
};
var queryCallbackFunction = (error: IFeedCallbackError, results: string[], options: IFeedCallbackOptions) => {
if (error) {
// the query was accepted and processed, but something went wrong
throw new Error("Error in query callback: " + error.body);
}
// we successfully received the customer IDs, so we can add them to the output array
outputArray.push({
productId: productId,
customerIds: results
});
}
var queryAccepted = collection.queryDocuments<string>(collection.getSelfLink(), query, queryCallbackFunction);
if (! queryAccepted) {
// the query wasn't accepted - this is likely because our stored procedure is running out of time in which to execute
throw new Error("Query was not accepted for product ID " + productId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment