You can send me a patch. the book is now on github. ;-) On Monday, 1 October 2012 13:05:08 UTC-5, monotasker wrote: > > Thanks Massimo. That's very clear now, and I do like the syntax (very > "pythonic"). I think an example like this would make a helpful addition to > the book. > > Ian > > On Monday, October 1, 2012 12:04:21 AM UTC-4, Massimo Di Pierro wrote: >> >> You must do >> >> db.tag_records.update_or_insert(condition, >> tlast_right=time_last_right) >> >> not condition can be an id >> >> condition = id >> >> can be a query >> >> condition = (db.tag_records.name==auth.user_id)&(db.tag_records.tag==tag) >> >> or it can be a dict of key:value >> >> condition = {'name': auth.user_id, 'tag': tag} >> >> If the first argument of update_or_insert is not specified the following >> named arguments (tlast_right=time_last_rightm,...) are used to build a >> condition dict. >> >> On Sunday, 30 September 2012 20:59:41 UTC-5, monotasker wrote: >>> >>> In the manual section on update_or_insert() the examples only touch on a >>> situation where one field/value is given as the matching condition. I'm >>> wondering what syntax needs to be used if we want to match values on more >>> than one field. Extrapolating from the manual example, can I do this? >>> >>> db.tag_records.update_or_insert(db.tag_records.name==auth.user_id, >>> db.tag_records.tag==tag, >>> tlast_right=time_last_right) >>> >>> Or should I provide a dictionary of matching fields/values (using the >>> syntax that Massimo mentioned in a thread in July): >>> >>> db.tag_records.update_or_insert({'name': auth.user_id, 'tag': tag}, >>> tlast_right=time_last_right) >>> >>> I actually like the latter syntax better. It's more concise and (to my >>> mind) differentiates more clearly between the matching values and the >>> update values. >>> >>> I also wonder whether this kind of situation would be worth mentioning >>> in the manual section? Assuming it's possible, this makes update_or_insert >>> quite powerful. >>> >>> Ian >>> >>
--