INNER CODE UNIT · JavaScript
checkQueryResult
scalar-labs/scalardb · core/src/main/resources/cosmosdb_stored_procedure/mutate.js:88
function checkQueryResult(mutation, record, reads) {
if (!reads || !reads.length) {
// The specified record does not exist
if (mutation == MUTATION.PUT || mutation == MUTATION.PUT_IF_NOT_EXISTS) {
return [deleteNullValues(record)];
} else {
// For other conditional mutations, the condition isn't satisfied
return [];
}
}
if (mutation == MUTATION.PUT_IF_NOT_EXISTS) {
return [];
} else if (mutation == MUTATION.PUT || mutation == MUTATION.PUT_IF) {
if (reads.length != 1) {
throw new Error("Unable to update multiple records.");
} else {
return [merge(reads[0], record)];