Пример #1
0
    def test_synonym_comparable(self):
        users = self.tables.users

        class User(object):

           class Comparator(PropComparator):
               pass

           def _getValue(self):
               return self._value

           def _setValue(self, value):
               setattr(self, '_value', value)

           value = property(_getValue, _setValue)

        mapper(User, users, properties={
            'uid':synonym('id'),
            'foobar':comparable_property(User.Comparator,User.value),
        })

        sess = create_session()
        u = User()
        u.name = 'ed'
        sess.add(u)
        sess.flush()
        sess.expunge(u)
        sess.merge(u)
Пример #2
0
    def test_synonym_comparable(self):
        users = self.tables.users

        class User(object):
            class Comparator(PropComparator):
                pass

            def _getValue(self):
                return self._value

            def _setValue(self, value):
                setattr(self, '_value', value)

            value = property(_getValue, _setValue)

        mapper(User,
               users,
               properties={
                   'uid': synonym('id'),
                   'foobar': comparable_property(User.Comparator, User.value),
               })

        sess = create_session()
        u = User()
        u.name = 'ed'
        sess.add(u)
        sess.flush()
        sess.expunge(u)
        sess.merge(u)
Пример #3
0
    def test_synonym_comparable(self):
        users = self.tables.users

        class User(object):
            class Comparator(PropComparator):
                pass

            def _getValue(self):
                return self._value

            def _setValue(self, value):
                setattr(self, "_value", value)

            value = property(_getValue, _setValue)

        mapper(
            User, users, properties={"uid": synonym("id"), "foobar": comparable_property(User.Comparator, User.value)}
        )

        sess = create_session()
        u = User()
        u.name = "ed"
        sess.add(u)
        sess.flush()
        sess.expunge(u)
        sess.merge(u)
Пример #4
0
class Fact(PolymorphicVerticalProperty, DeclarativeBase):
    """ A polymorphic-valued vertical table property """
    __tablename__ = 'moksha_facts'

    id = Column(Integer, ForeignKey('moksha_entities.id'), primary_key=True)
    key = Column(Unicode(64), primary_key=True)
    type_ = Column(Unicode(16), default=None)
    int_value = Column(Integer, default=None)
    char_value = Column(UnicodeText, default=None)
    boolean_value = Column(Boolean, default=None)
    datetime_value = Column(DateTime, default=None)
    list_value = Column(PickleType, default=None)
    dict_value = Column(PickleType, default=None)

    value = comparable_property(PolymorphicVerticalProperty.Comparator,
                                PolymorphicVerticalProperty.value)

    type_map = {
        int: (u'integer', 'int_value'),
        str: (u'char', 'char_value'),
        unicode: (u'char', 'char_value'),
        bool: (u'boolean', 'boolean_value'),
        datetime: (u'datetime', 'datetime_value'),
        list: (u'list', 'list_value'),
        dict: (u'dict', 'dict_value'),
        type(None): (None, None),
    }
Пример #5
0
 def decorate(fn):
     return comparable_property(comparator_factory, fn)
Пример #6
0
 def decorate(fn):
     return comparable_property(comparator_factory, fn)
Пример #7
0
            return '<%s %r>' % (self.__class__.__name__, self.name)

    mapper(Animal,
           animals,
           properties={
               'facts':
               relation(AnimalFact,
                        backref='animal',
                        collection_class=attribute_mapped_collection('key')),
           })

    mapper(AnimalFact,
           chars,
           properties={
               'value':
               comparable_property(AnimalFact.Comparator, AnimalFact.value)
           })

    metadata.bind = 'sqlite:///'
    metadata.create_all()
    session = create_session()

    stoat = Animal(u'stoat')
    stoat[u'color'] = u'red'
    stoat[u'cuteness'] = 7
    stoat[u'weasel-like'] = True

    session.save(stoat)
    session.flush()
    session.clear()
Пример #8
0
        def __init__(self, name):
            self.name = name

        def __repr__(self):
            return '<%s %r>' % (self.__class__.__name__, self.name)


    mapper(Animal, animals, properties={
        'facts': relation(
            AnimalFact, backref='animal',
            collection_class=attribute_mapped_collection('key')),
        })

    mapper(AnimalFact, chars, properties={
        'value': comparable_property(AnimalFact.Comparator, AnimalFact.value)
        })

    metadata.bind = 'sqlite:///'
    metadata.create_all()
    session = create_session()

    stoat = Animal(u'stoat')
    stoat[u'color'] = u'red'
    stoat[u'cuteness'] = 7
    stoat[u'weasel-like'] = True

    session.save(stoat)
    session.flush()
    session.clear()