Beispiel #1
0
    def test_single_entity_frozen(self):
        s = fixture_session()
        User = self.classes.User

        stmt = select(User).where(User.id.in_([7, 8, 9])).order_by(User.id)
        result = s.execute(stmt)
        it = loading.merge_frozen_result(s, stmt, result.freeze())
        eq_([x.id for x in it().scalars()], [7, 8, 9])
Beispiel #2
0
    def test_entity_col_mix_plain_tuple_frozen(self):
        s = fixture_session()
        User = self.classes.User

        stmt = (select(User,
                       User.id).where(User.id.in_([7, 8,
                                                   9])).order_by(User.id))
        result = s.execute(stmt)

        it = loading.merge_frozen_result(s, stmt, result.freeze())
        it = list(it())
        eq_([(x.id, y) for x, y in it], [(7, 7), (8, 8), (9, 9)])
        eq_(list(it[0]._mapping.keys()), ["User", "id"])
Beispiel #3
0
    def _do_orm_execute(self, orm_context):

        for opt in orm_context.user_defined_options:
            if isinstance(opt, RelationshipCache):
                opt = opt._process_orm_context(orm_context)
                if opt is None:
                    continue

            if isinstance(opt, FromCache):
                dogpile_region = self.cache_regions[opt.region]

                our_cache_key = opt._generate_cache_key(
                    orm_context.statement, orm_context.parameters, self
                )

                if opt.ignore_expiration:
                    cached_value = dogpile_region.get(
                        our_cache_key,
                        expiration_time=opt.expiration_time,
                        ignore_expiration=opt.ignore_expiration,
                    )
                else:

                    def createfunc():
                        return orm_context.invoke_statement().freeze()

                    cached_value = dogpile_region.get_or_create(
                        our_cache_key,
                        createfunc,
                        expiration_time=opt.expiration_time,
                    )

                if cached_value is NO_VALUE:
                    # keyerror?   this is bigger than a keyerror...
                    raise KeyError()

                orm_result = loading.merge_frozen_result(
                    orm_context.session,
                    orm_context.statement,
                    cached_value,
                    load=False,
                )
                return orm_result()

        else:
            return None