On Feb 21, 2014, at 5:48 PM, Jonathan Vanasco <jonat...@findmeon.com> wrote:
> i currently have a table that looks like this: > > > class MyTable(DeclaredTable): > id = sa.Column(sa.Integer, primary_key=True) > features_enabled = sa.Column(sa.Integer, nullable=False, default=0, ) > _feature_manager = None > > @property > def feature_manager(self): > if self._feature_manager is None: > _feature_manager = FeatureManager( features_enabled ) > return _feature_manager > > In this example, FeatureManager is a class that allows for some bitwise > operations by passing in text values. ( the text values and bitwise id are > stored in another table ) > > I was looking at making features_enabled a custom type that automatically > created/decoded the FeatureManager() class. > > I got lost on this part: > > here we see `class MyType(sqlalchemy.types.TypeDecorator)` > > http://docs.sqlalchemy.org/en/rel_0_9/core/types.html#augmenting-existing-types > > but then here we see `class MyInt(sqlalchemy.Integer)` > > http://docs.sqlalchemy.org/en/rel_0_9/core/types.html#redefining-and-creating-new-operators > > which would be more appropriate for my usage ? that one is TypeDecorator. You want an Integer as far as how the database communication proceeds, then on top you are adding a FeatureManager object. TypeDecorator can be used to create new operators too in the same way as a direct type subclass, if you’re interested in that.
signature.asc
Description: Message signed with OpenPGP using GPGMail