I’m trying to implement a “create or update” function for my ottoman models, after getting my feet wet and already having built a number of models successfully.
An issue I’m running into is a “natural key” for models that a user might send. Suppose someone POSTs something to my REST API; clearly I don’t know what the couchbase key is going to be. My model might have an auto-assigned uuid, but the user isn’t POSTing that because it’s my job to generate it. So I can’t look something up by that key. How then, given a JSON document from a user and an Ottoman model type, can I figure out whether I already have this item so as to update one in place rather than creating a new duplicate?
Additionally, has anyone looked into wrapping Ottoman functions in promises rather than using the standard callback(error, results)? In our code base we’re already using promises quite a bit, and using Ottoman callbacks introduces a different sort of mixed style; alternatively, if there’s a best practice on how to use something existing like bluebird to “promisify” Ottoman, I’d love to hear about it.
Thanks