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


Python sqlalchemy_utils.sort_query函数代码示例

本文整理汇总了Python中sqlalchemy_utils.sort_query函数的典型用法代码示例。如果您正苦于以下问题:Python sort_query函数的具体用法?Python sort_query怎么用?Python sort_query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_column_property

    def test_column_property(self, session, TextItem):
        TextItem.item_count = sa.orm.column_property(
            sa.select([sa.func.count("1")]).select_from(TextItem.__table__).label("item_count")
        )

        query = sort_query(session.query(TextItem), "item_count")
        assert_contains("ORDER BY item_count", query)
开发者ID:kvesteri,项目名称:sqlalchemy-utils,代码行数:7,代码来源:test_sort_query.py

示例2: test_relation_hybrid_property

 def test_relation_hybrid_property(self):
     query = (
         self.session.query(self.Article)
         .join(self.Article.category)
     ).group_by(self.Article.id)
     query = sort_query(query, '-category-articles_count')
     assert_contains('ORDER BY (SELECT count(article.id) AS count_1', query)
开发者ID:bjmc,项目名称:sqlalchemy-utils,代码行数:7,代码来源:test_sort_query.py

示例3: test_join

 def test_join(self, session, Article):
     query = (
         session.query(Article)
         .join(Article.category)
     )
     query = sort_query(query, 'name', silent=False)
     assert_contains('ORDER BY article.name ASC', query)
开发者ID:JackWink,项目名称:sqlalchemy-utils,代码行数:7,代码来源:test_sort_query.py

示例4: test_join

 def test_join(self):
     query = (
         self.session.query(self.Article)
         .join(self.Article.category)
     )
     query = sort_query(query, 'name', silent=False)
     assert 'ORDER BY article.name ASC' in str(query)
开发者ID:adarshk7,项目名称:sqlalchemy-utils,代码行数:7,代码来源:test_sort_query.py

示例5: test_with_mapper_and_column_property

    def test_with_mapper_and_column_property(self):
        class Apple(self.Base):
            __tablename__ = 'apple'
            id = sa.Column(sa.Integer, primary_key=True)
            article_id = sa.Column(sa.Integer, sa.ForeignKey(self.Article.id))

        self.Article.apples = sa.orm.relationship(Apple)

        self.Article.apple_count = sa.orm.column_property(
            sa.select([sa.func.count(Apple.id)])
            .where(Apple.article_id == self.Article.id)
            .correlate(self.Article.__table__)
            .label('apple_count'),
            deferred=True
        )
        query = (
            self.session.query(sa.inspect(self.Article))
            .outerjoin(self.Article.apples)
            .options(
                sa.orm.undefer(self.Article.apple_count)
            )
            .options(sa.orm.contains_eager(self.Article.apples))
        )
        query = sort_query(query, 'apple_count')
        assert 'ORDER BY apple_count' in str(query)
开发者ID:bjmc,项目名称:sqlalchemy-utils,代码行数:25,代码来源:test_sort_query.py

示例6: test_hybrid_property_descending

 def test_hybrid_property_descending(self):
     query = self.session.query(self.Category)
     query = sort_query(query, '-articles_count')
     assert (
         'ORDER BY (SELECT count(article.id) AS count_1'
     ) in str(query)
     assert ' DESC' in str(query)
开发者ID:adarshk7,项目名称:sqlalchemy-utils,代码行数:7,代码来源:test_sort_query.py

示例7: test_assigned_hybrid_property

    def test_assigned_hybrid_property(self, session, Article):
        def getter(self):
            return self.name

        Article.some_hybrid = sa.ext.hybrid.hybrid_property(fget=getter)
        query = session.query(Article)
        query = sort_query(query, "some_hybrid")
        assert_contains("ORDER BY article.name ASC", query)
开发者ID:kvesteri,项目名称:sqlalchemy-utils,代码行数:8,代码来源:test_sort_query.py

示例8: test_with_unknown_column

 def test_with_unknown_column(self):
     query = sort_query(
         self.session.query(
             sa.orm.with_polymorphic(self.TextItem, [self.BlogPost])
         ),
         'category'
     )
     assert 'ORDER BY' not in str(query)
开发者ID:bjmc,项目名称:sqlalchemy-utils,代码行数:8,代码来源:test_sort_query.py

示例9: test_with_existing_column

 def test_with_existing_column(self):
     query = sort_query(
         self.session.query(
             sa.orm.with_polymorphic(self.TextItem, [self.Article])
         ),
         'category'
     )
     assert 'ORDER BY' in str(query)
开发者ID:bjmc,项目名称:sqlalchemy-utils,代码行数:8,代码来源:test_sort_query.py

示例10: test_without_sort_param_returns_the_query_object_untouched

 def test_without_sort_param_returns_the_query_object_untouched(
     self,
     session,
     Article
 ):
     query = session.query(Article)
     query = sort_query(query, '')
     assert query == query
开发者ID:JackWink,项目名称:sqlalchemy-utils,代码行数:8,代码来源:test_sort_query.py

示例11: test_relation_hybrid_property

 def test_relation_hybrid_property(self):
     query = (
         self.session.query(self.Article)
         .join(self.Article.category)
         .correlate(self.Article.__table__)
     )
     query = sort_query(query, '-category-articles_count')
     assert 'ORDER BY (SELECT count(article.id) AS count_1' in str(query)
开发者ID:adarshk7,项目名称:sqlalchemy-utils,代码行数:8,代码来源:test_sort_query.py

示例12: test_column_property_descending

    def test_column_property_descending(self, session, Article, Category):
        Category.article_count = sa.orm.column_property(
            sa.select([sa.func.count(Article.id)]).where(Article.category_id == Category.id).label("article_count")
        )

        query = session.query(Category)
        query = sort_query(query, "-article_count")
        assert_contains("article_count DESC", query)
开发者ID:kvesteri,项目名称:sqlalchemy-utils,代码行数:8,代码来源:test_sort_query.py

示例13: test_aliased_joined_entity

 def test_aliased_joined_entity(self, session, Article, Category):
     alias = sa.orm.aliased(Category, name='categories')
     query = session.query(
         Article
     ).join(
         alias, Article.category
     )
     query = sort_query(query, '-categories-name')
     assert_contains('ORDER BY categories.name DESC', query)
开发者ID:JackWink,项目名称:sqlalchemy-utils,代码行数:9,代码来源:test_sort_query.py

示例14: test_aliased_hybrid_property

 def test_aliased_hybrid_property(self):
     alias = sa.orm.aliased(self.Category, name="categories")
     query = (
         self.session.query(self.Article)
         .outerjoin(alias, self.Article.category)
         .options(sa.orm.contains_eager(self.Article.category, alias=alias))
     )
     query = sort_query(query, "-categories-articles_count")
     assert "ORDER BY (SELECT count(article.id) AS count_1" in str(query)
开发者ID:kevans05,项目名称:internetAlarmClock,代码行数:9,代码来源:test_sort_query.py

示例15: test_aliased_joined_entity

 def test_aliased_joined_entity(self):
     alias = sa.orm.aliased(self.Category, name='categories')
     query = self.session.query(
         self.Article
     ).join(
         alias, self.Article.category
     )
     query = sort_query(query, '-categories-name')
     assert 'ORDER BY categories.name DESC' in str(query)
开发者ID:adarshk7,项目名称:sqlalchemy-utils,代码行数:9,代码来源:test_sort_query.py


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