Storing models
sqlalchemy_mutable.model_shell.Query
class sqlalchemy_mutable.model_shell.Query(scoped_session) [source]
Query attribute in database model. Models which have a query
attribute
will be unshelled automatically when stored and recovered in a Mutable
object. See the setup code.
Parameters: | scoped_session : sqlalchemy.orm.scoping.scoped_session
Current scoped session. |
---|---|
Attributes: | scoped_session : sqlalchemy.orm.scoping.scoped_session
Set from the |
sqlalchemy_mutable.model_shell.ModelShell
class sqlalchemy_mutable.model_shell.ModelShell(model) [source]
The ModelShell
stores (shells) and recovers (unshells) database
models in Mutable
objects and MutableType
columns.
Parameters: | model : sqlalchemy.ext.declarative.api.Base
Database model to store. |
---|---|
Attributes: | id : usually int or str
Identity of the model. model_class : classClass of the stored model. |
Notes
- The model must have an identity before it is shelled. i.e you must add it to the session and commit or flush it.
- Models are unshelled to make comparisons the
__eq__
comparison.
Examples
Make sure you have run the setup code.
from sqlalchemy_mutable.model_shell import ModelShell
model = MyModel()
session.add(model)
session.commit()
shell = ModelShell(model)
shell.unshell()
Out:
<__main__.MyModel at 0x7f6bd9936c50>
Methods
unshell(self) [source]
Recover (unshell) a model.
Returns: | model or (model_class, id) :
If the original model has a |
---|