Mutable dictionary
Notes
In the setup code, we use a MutableType
database column, which handles
dictionaries as well as other objects. To force the column to be a
dictionary, substitute MutableDictType
or MutableDictJSONType
for
MutableType
.
Examples
Make sure you have run the setup code.
model = MyModel()
model.mutable = {}
session.add(model)
session.commit()
# without a mutable dictionary,
# this change will not survive a commit
model.mutable['hello'] = 'world'
session.commit()
model.mutable
Out:
{'hello': 'world'}
sqlalchemy_mutable.MutableDictType
Mutable dictionary database type with pickle serialization.
sqlalchemy_mutable.MutableDictJSONType
Mutable dictionary database type with JSON serialization.
sqlalchemy_mutable.MutableDict
class sqlalchemy_mutable.MutableDict(source={}, root=None) [source]
Subclasses dict
, and implements all dict
methods.
Parameters: | source : dict, default={}
Source object which will be converted into a mutable dictionary. root : sqlalchemy_mutable.Mutable or None, default=None
Root mutable object. If |
---|
Methods
unshell(self) [source]
Call to force values to unshell. Normally this occurs automatically.
Returns: | copy : dict
Shallow copy of |
---|