Source code for tinydb.operations

"""A collection of update operations for TinyDB.They are used for updates like this:>>> db.update(delete('foo'), where('foo') == 2)This would delete the ``foo`` field from all documents where ``foo`` equals 2."""
[docs]defdelete(field):""" Delete a given field from the document. """deftransform(doc):deldoc[field]returntransform
[docs]defadd(field,n):""" Add ``n`` to a given field in the document. """deftransform(doc):doc[field]+=nreturntransform
[docs]defsubtract(field,n):""" Subtract ``n`` to a given field in the document. """deftransform(doc):doc[field]-=nreturntransform
[docs]defset(field,val):""" Set a given field to ``val``. """deftransform(doc):doc[field]=valreturntransform
[docs]defincrement(field):""" Increment a given field in the document by 1. """deftransform(doc):doc[field]+=1returntransform
[docs]defdecrement(field):""" Decrement a given field in the document by 1. """deftransform(doc):doc[field]-=1returntransform