• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sqlalchemy_utils.sort_query函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_aliased_hybrid_property

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


示例17: test_aliased_concat_hybrid_property

 def test_aliased_concat_hybrid_property(self, session, Article, Category):
     alias = sa.orm.aliased(Category, name="aliased")
     query = (
         session.query(Article)
         .outerjoin(alias, Article.category)
         .options(sa.orm.contains_eager(Article.category, alias=alias))
     )
     query = sort_query(query, "aliased-full_name")
     assert_contains("concat(aliased.title, %(concat_1)s, aliased.name)", query)
开发者ID:kvesteri,项目名称:sqlalchemy-utils,代码行数:9,代码来源:test_sort_query.py


示例18: test_assigned_hybrid_property

    def test_assigned_hybrid_property(self):
        def getter(self):
            return self.name

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


示例19: test_column_property_descending

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

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


示例20: test_column_property

    def test_column_property(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 ASC', query)
开发者ID:JackWink,项目名称:sqlalchemy-utils,代码行数:10,代码来源:test_sort_query.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python functions.create_database函数代码示例发布时间:2022-05-27
下一篇:
Python sqlalchemy_utils.get_mapper函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap