Mutable tuple
Notes
In the setup code, we use a MutableType
database column that handles tuples
as well as other objects. To force the column to be a tuple, substitute MutableTupleType
or MutableTupleJSONType
for MutableType
.
Examples
Make sure you have run the setup code.
model0 = MyModel()
model1 = MyModel()
model0.mutable = [(model1,)]
session.add_all([model0, model1])
session.commit()
# without a mutable tuple,
# this change would not appear after a commit
model1.greeting = 'hello world'
session.commit()
model0.mutable[0][0].greeting
Out:
'hello world'
sqlalchemy_mutable.MutableTupleType
Mutable tuple database type with pickle serialization.
sqlalchemy_mutable.MutableTupleJSONType
Mutable tuple database type with JSON serialization.
sqlalchemy_mutable.MutableTuple
Parameters: | source : tuple, default=()
Source objects that will be converted into a mutable tuple. root : sqlalchemy.Mutable or None, default=None
Root mutable object. If |
---|
Methods
coerce(cls, key, obj) [source]
unshell(self) [source]
Call to force values to unshell. Normally, this occurs automatically.
Returns: | copy : tuple
Shallow copy of |
---|