Mutable list
Notes
In the setup code, we use a MutableType
database column, which handles
lists as well as other objects. To force the column to be a list,
substitute MutableListType
or MutableListJSONType
for MutableType
.
Examples
Make sure you have run the setup code.
model = MyModel()
model.mutable = []
session.add(model)
session.commit()
# without a mutable list,
# this change will not survive a commit
model.mutable.append('hello world')
session.commit()
model.mutable
Out:
['hello world']
sqlalchemy_mutable.MutableListType
Mutable list database type with pickle serialization.
sqlalchemy_mutable.MutableListJSONType
Mutable list database type with JSON serialization.
sqlalchemy_mutable.MutableList
class sqlalchemy_mutable.MutableList(source=[], root=None) [source]
Subclasses list
, and implements all list
methods.
Parameters: | source : list, default=[]
Source objects which will be converted into a mutable list. root : sqlalchemy.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 : list
Shallow copy of |
---|