当前位置: 首页>>代码示例>>Python>>正文


Python orm.undefer方法代码示例

本文整理汇总了Python中sqlalchemy.orm.undefer方法的典型用法代码示例。如果您正苦于以下问题:Python orm.undefer方法的具体用法?Python orm.undefer怎么用?Python orm.undefer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.orm的用法示例。


在下文中一共展示了orm.undefer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def __call__(self):
        lecture = self.db.query(models.Lecture).options(undefer('tutorials.student_count')).get(self.lecture_id)
        names = self.request.config['lecture_types'][lecture.type]
        pref_subjects = lecture.pref_subjects()
        pref_count = sum([pref[0] for pref in pref_subjects])
        subjects = lecture.subjects()
        student_count = sum([subj[0] for subj in subjects])
        times = lecture.prepareTimePreferences(user=None)
        times = sorted([t for t in times], key=lambda s:s['time'].value)
        #print(times)
        return {'lecture': lecture,
                'names': names,
                'pref_subjects': pref_subjects,
                'pref_count': pref_count,
                'subjects': subjects,
                'times': times,
                'student_count': student_count,
                'categories': utils.categories,
                'exams': dict([[cat['id'], lecture.exams.filter(models.Exam.category==cat['id'])] for cat in utils.categories]),
                } 
开发者ID:muesli-hd,项目名称:muesli,代码行数:22,代码来源:viewsLecture.py

示例2: refresh_profile

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def refresh_profile(orcid_id, high_priority=False):
    print u"refreshing {}".format(orcid_id)

    my_person = Person.query.options(orm.undefer('*')).filter_by(orcid_id=orcid_id).first()

    # for testing on jason's local, so it doesn't have to do a real refresh
    # sleep(5)
    # return my_person

    my_person.refresh(high_priority=high_priority)
    db.session.merge(my_person)

    commit_success = safe_commit(db)
    if commit_success:
        print u"committed {}".format(orcid_id)
    else:
        print u"COMMIT fail on {}".format(orcid_id)

    return my_person 
开发者ID:ourresearch,项目名称:impactstory-tng,代码行数:21,代码来源:person.py

示例3: test_load_only_w_deferred

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def test_load_only_w_deferred(self):
        orders, Order = self.tables.orders, self.classes.Order

        mapper(
            Order,
            orders,
            properties={"description": deferred(orders.c.description)},
        )

        sess = create_session()
        q = sess.query(Order).options(
            load_only("isopen", "description"), undefer("user_id")
        )
        self.assert_compile(
            q,
            "SELECT orders.description AS orders_description, "
            "orders.id AS orders_id, "
            "orders.user_id AS orders_user_id, "
            "orders.isopen AS orders_isopen FROM orders",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:test_deferred.py

示例4: test_defer_on_wildcard_subclass

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def test_defer_on_wildcard_subclass(self):
        # pretty much the same as load_only except doesn't
        # exclude the primary key

        # TODO: what is ".*"?  this is not documented anywhere, how did this
        # get implemented without docs ?  see #4390
        s = Session()
        q = (
            s.query(Manager)
            .order_by(Person.person_id)
            .options(defer(".*"), undefer("status"))
        )
        self.assert_compile(
            q,
            "SELECT managers.status AS managers_status "
            "FROM people JOIN managers ON "
            "people.person_id = managers.person_id ORDER BY people.person_id",
        )

        # note this doesn't apply to "bound" loaders since they don't seem
        # to have this ".*" featue. 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_deferred.py

示例5: get_packages

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def get_packages(self, collection, only_new=False):
        """
        Get packages eligible for resolution in new repo for given collection.

        :param: collection collection for which packages are requested
        :param: only_new whether to consider only packages that weren't
                         resolved yet
        """
        query = (
            self.db.query(Package)
            .filter(~Package.blocked)
            .filter(Package.tracked)
            .filter(~Package.skip_resolution)
            .filter(Package.collection_id == collection.id)
            .filter(Package.last_complete_build_id != None)
            .options(joinedload(Package.last_build))
            .options(undefer('last_build.dependency_keys'))
        )
        if only_new:
            query = query.filter(Package.resolved == None)
        return query.all() 
开发者ID:fedora-infra,项目名称:koschei,代码行数:23,代码来源:repo_resolver.py

示例6: fetch_queue_chunk

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def fetch_queue_chunk(self, chunk_size):
        logger.info(u"looking for new jobs")

        text_query_pattern = """
                        with update_chunk as (
                            select url
                            from {queue_table}
                            where started is null
                            order by retry_at nulls first, finished nulls first, started, rand
                            limit {chunk_size}
                            for update skip locked
                        )
                        update {queue_table} queue_rows_to_update
                        set started=now()
                        from update_chunk
                        where update_chunk.url = queue_rows_to_update.url
                        returning update_chunk.url;
                    """
        text_query = text_query_pattern.format(
            chunk_size=chunk_size,
            queue_table=self.table_name(None)
        )

        logger.info(u"the queue query is:\n{}".format(text_query))

        job_time = time()
        row_list = db.engine.execute(text(text_query).execution_options(autocommit=True)).fetchall()
        object_ids = [row[0] for row in row_list]
        logger.info(u"got ids, took {} seconds".format(elapsed(job_time)))

        job_time = time()
        q = db.session.query(PdfUrl).options(orm.undefer('*')).filter(PdfUrl.url.in_(object_ids))
        objects = q.all()
        logger.info(u"got pdf_url objects in {} seconds".format(elapsed(job_time)))

        random.shuffle(objects)
        return objects 
开发者ID:ourresearch,项目名称:oadoi,代码行数:39,代码来源:queue_pdf_url_check.py

示例7: _process

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def _process(self):
        query = (Category.query
                 .filter(Category.title_matches(request.args['term']),
                         ~Category.is_deleted)
                 .options(undefer('chain_titles'))
                 .order_by(Category.title))
        results = [{
            'title': category.title,
            'path': category.chain_titles[1:-1],
            'url': unicode(category.url)
        } for category in query.limit(7)]
        return jsonify(success=True, results=results, count=query.count()) 
开发者ID:indico,项目名称:indico-plugins,代码行数:14,代码来源:controllers.py

示例8: get

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def get(self, test_id: str):
        testcase = TestCase.query.options(undefer("message"), joinedload("job")).get(
            test_id
        )

        schema = TestCaseSchema()
        return self.respond_with_schema(schema, testcase) 
开发者ID:getsentry,项目名称:zeus,代码行数:9,代码来源:test_details.py

示例9: get

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def get(self):
        """
        ---
        get:
          security:
            - Bearer: [read]
            - Basic: [read]
          tags:
            - "v1"
          summary: "return a specific lecture"
          description: ""
          operationId: "lecture_get"
          produces:
            - "application/json"
          responses:
            200:
              description: successfull return of the lecture
              schema:
                $ref: "#/definitions/Lecture"
        """
        lecture_id = self.request.matchdict['lecture_id']
        lecture = self.db.query(models.Lecture).options(undefer('tutorials.student_count'), joinedload(models.Lecture.assistants), joinedload(models.Lecture.tutorials)).get(lecture_id)
        subscribed = self.request.user.id in [s.id for s in lecture.students]
        allowed_attr = allowed_attributes.lecture()
        if lecture.mode == 'off':
            allowed_attr = allowed_attributes.lecture()
            allowed_attr.remove('tutorials')
        schema = models.LectureSchema(only=allowed_attr)
        response = schema.dump(lecture)
        if lecture.mode == 'off':
            response.update({'tutorials': []})
        return {'lecture': response,
                'subscribed': subscribed} 
开发者ID:muesli-hd,项目名称:muesli,代码行数:35,代码来源:lectureEndpoint.py

示例10: test_undefer_star

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def test_undefer_star(self):
        orders, Order = self.tables.orders, self.classes.Order

        mapper(
            Order,
            orders,
            properties=util.OrderedDict(
                [
                    ("userident", deferred(orders.c.user_id)),
                    ("description", deferred(orders.c.description)),
                    ("opened", deferred(orders.c.isopen)),
                ]
            ),
        )

        sess = create_session()
        q = sess.query(Order).options(Load(Order).undefer("*"))
        self.assert_compile(
            q,
            "SELECT orders.user_id AS orders_user_id, "
            "orders.description AS orders_description, "
            "orders.isopen AS orders_isopen, "
            "orders.id AS orders_id, "
            "orders.address_id AS orders_address_id "
            "FROM orders",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:28,代码来源:test_deferred.py

示例11: test_defer_addtl_attrs

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def test_defer_addtl_attrs(self):
        users, User, Address, addresses = (
            self.tables.users,
            self.classes.User,
            self.classes.Address,
            self.tables.addresses,
        )

        mapper(Address, addresses)
        mapper(
            User,
            users,
            properties={
                "addresses": relationship(
                    Address, lazy="selectin", order_by=addresses.c.id
                )
            },
        )

        sess = create_session()

        with testing.expect_deprecated(
            r"The \*addl_attrs on orm.defer is deprecated.  "
            "Please use method chaining"
        ):
            sess.query(User).options(defer("addresses", "email_address"))

        with testing.expect_deprecated(
            r"The \*addl_attrs on orm.undefer is deprecated.  "
            "Please use method chaining"
        ):
            sess.query(User).options(undefer("addresses", "email_address")) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:34,代码来源:test_deprecations.py

示例12: test_state_deferred_to_col

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def test_state_deferred_to_col(self):
        """Behavioral test to verify the current activity of loader callables
        """

        users, User = self.tables.users, self.classes.User

        mapper(User, users, properties={"name": deferred(users.c.name)})

        sess = create_session()
        u1 = sess.query(User).options(undefer(User.name)).first()
        assert "name" not in attributes.instance_state(u1).callables

        # mass expire, the attribute was loaded,
        # the attribute gets the callable
        sess.expire(u1)
        assert "name" in attributes.instance_state(u1).expired_attributes
        assert "name" not in attributes.instance_state(u1).callables

        # load it
        u1.name
        assert "name" not in attributes.instance_state(u1).expired_attributes
        assert "name" not in attributes.instance_state(u1).callables

        # mass expire, attribute was loaded but then deleted,
        # the callable goes away - the state wants to flip
        # it back to its "deferred" loader.
        sess.expunge_all()
        u1 = sess.query(User).options(undefer(User.name)).first()
        del u1.name
        sess.expire(u1)
        assert "name" in attributes.instance_state(u1).expired_attributes
        assert "name" not in attributes.instance_state(u1).callables

        # single attribute expire, the attribute gets the callable
        sess.expunge_all()
        u1 = sess.query(User).options(undefer(User.name)).first()
        sess.expire(u1, ["name"])

        # the expire cancels the undefer
        assert "name" in attributes.instance_state(u1).expired_attributes
        assert "name" not in attributes.instance_state(u1).callables 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:43,代码来源:test_expire.py

示例13: test_deferred_cols_missing_in_load_state_reset

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def test_deferred_cols_missing_in_load_state_reset(self):
        Data = self.classes.DataDefer

        sess = create_session()

        d1 = Data(data="d1")
        sess.add(d1)
        sess.flush()
        sess.close()

        sess = create_session()
        d1 = (
            sess.query(Data)
            .from_statement(select([Data.id]))
            .options(undefer(Data.data))
            .first()
        )
        d1.data = "d2"

        # the deferred loader has to clear out any state
        # on the col, including that 'd2' here
        d1 = sess.query(Data).populate_existing().first()

        def go():
            eq_(d1.data, "d1")

        self.assert_sql_count(testing.db, go, 1) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:29,代码来源:test_expire.py

示例14: get_prev_build_for_comparison

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def get_prev_build_for_comparison(self, build):
        """
        Finds a preceding build of the same package that is suitable to be
        compared against.
        """
        return (
            self.db.query(Build)
            .filter_by(package_id=build.package_id)
            .filter(Build.started < build.started)
            .filter(Build.deps_resolved == True)
            .order_by(Build.started.desc())
            .options(undefer('dependency_keys'))
            .first()
        ) 
开发者ID:fedora-infra,项目名称:koschei,代码行数:16,代码来源:resolver.py

示例15: fetch_queue_chunk

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import undefer [as 别名]
def fetch_queue_chunk(self, chunk_size, queue_no):
        logger.info(u"looking for new jobs")

        text_query_pattern = u'''
            with refresh_queue as (
                select id
                from {queue_table}
                where
                    queue_no = {queue_no}
                    and started is null
                order by
                    priority desc,
                    finished asc nulls first,
                    rand
                limit {chunk_size}
                for update skip locked
            )
            update {queue_table} queue_rows_to_update
            set started = now()
            from refresh_queue
            where refresh_queue.id = queue_rows_to_update.id
            returning refresh_queue.id;
        '''

        text_query = text_query_pattern.format(
            chunk_size=chunk_size,
            queue_table=self.table_name(None),
            queue_no=queue_no
        )

        logger.info(u"the queue query is:\n{}".format(text_query))

        job_time = time()
        row_list = db.engine.execute(text(text_query).execution_options(autocommit=True)).fetchall()
        object_ids = [row[0] for row in row_list]
        logger.info(u"got {} ids, took {} seconds".format(len(object_ids), elapsed(job_time)))

        job_time = time()
        q = db.session.query(Pub).options(
            orm.undefer('*')
        ).filter(Pub.id.in_(object_ids))

        objects = q.all()
        logger.info(u"got pub objects in {} seconds".format(elapsed(job_time)))

        return objects 
开发者ID:ourresearch,项目名称:oadoi,代码行数:48,代码来源:queue_pub_refresh_aux.py


注:本文中的sqlalchemy.orm.undefer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。