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


Python orm.load_only方法代码示例

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


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

示例1: wbgetentities

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def wbgetentities(self, debug=False):
        sub = (session.query(Item.item_id)
                      .join(ItemTag)
                      .group_by(Item.item_id)
                      .subquery())
        q = (self.items.filter(Item.item_id == sub.c.item_id)
                       .options(load_only(Item.qid)))

        if debug:
            print('running wbgetentities query')
            print(q)
            print(q.count())
        items = {i.qid: i for i in q}
        if debug:
            print('{} items'.format(len(items)))

        for qid, entity in wikidata_api.entity_iter(items.keys(), debug=debug):
            if debug:
                print(qid)
            items[qid].entity = entity 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:22,代码来源:place.py

示例2: single_item_query

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def single_item_query(self, loadonly=None):
        """A query representing the single item referenced by the request.

        **URL (matchdict) Parameters**

            **id** (*str*): resource id

        Returns:
            sqlalchemy.orm.query.Query: query which will fetch item with id
            'id'.
        """
        if not loadonly:
            loadonly = self.allowed_requested_query_columns.keys()
        return self.dbsession.query(
            self.model
        ).options(
            load_only(*loadonly)
        ).filter(
            self.id_col(self.model) == self.obj_id
        ) 
开发者ID:colinhiggs,项目名称:pyramid-jsonapi,代码行数:22,代码来源:collection_view.py

示例3: object_exists

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def object_exists(self, obj_id):
        """Test if object with id obj_id exists.

        Args:
            obj_id (str): object id

        Returns:
            bool: True if object exists, False if not.
        """
        try:
            item = self.dbsession.query(
                self.model
            ).options(
                load_only(self.key_column.name)
            ).get(obj_id)
        except (sqlalchemy.exc.DataError, sqlalchemy.exc.StatementError):
            item = False
        return bool(item) 
开发者ID:colinhiggs,项目名称:pyramid-jsonapi,代码行数:20,代码来源:collection_view.py

示例4: test_load_only_w_deferred

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [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

示例5: test_present_overrides_deferred

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def test_present_overrides_deferred(self):
        Node = self.classes.Node

        session = Session()

        q = session.query(Node).options(
            joinedload(Node.parent).load_only(Node.id, Node.parent_id)
        )

        # Node #1 will appear first as Node.parent and have
        # deferred applied to Node.name.  it will then appear
        # as Node in the last row and "name" should be populated.
        nodes = q.order_by(Node.id.desc()).all()

        def go():
            for node in nodes:
                eq_(node.name, "name")

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

示例6: test_load_only_subclass

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def test_load_only_subclass(self):
        s = Session()
        q = (
            s.query(Manager)
            .order_by(Manager.person_id)
            .options(load_only("status", "manager_name"))
        )
        self.assert_compile(
            q,
            "SELECT managers.person_id AS managers_person_id, "
            "people.person_id AS people_person_id, "
            "people.type AS people_type, "
            "managers.status AS managers_status, "
            "managers.manager_name AS managers_manager_name "
            "FROM people JOIN managers "
            "ON people.person_id = managers.person_id "
            "ORDER BY managers.person_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_deferred.py

示例7: test_load_only_subclass_bound

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def test_load_only_subclass_bound(self):
        s = Session()
        q = (
            s.query(Manager)
            .order_by(Manager.person_id)
            .options(Load(Manager).load_only("status", "manager_name"))
        )
        self.assert_compile(
            q,
            "SELECT managers.person_id AS managers_person_id, "
            "people.person_id AS people_person_id, "
            "people.type AS people_type, "
            "managers.status AS managers_status, "
            "managers.manager_name AS managers_manager_name "
            "FROM people JOIN managers "
            "ON people.person_id = managers.person_id "
            "ORDER BY managers.person_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_deferred.py

示例8: test_load_only_subclass_and_superclass

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def test_load_only_subclass_and_superclass(self):
        s = Session()
        q = (
            s.query(Boss)
            .order_by(Person.person_id)
            .options(load_only("status", "manager_name"))
        )
        self.assert_compile(
            q,
            "SELECT managers.person_id AS managers_person_id, "
            "people.person_id AS people_person_id, "
            "people.type AS people_type, "
            "managers.status AS managers_status, "
            "managers.manager_name AS managers_manager_name "
            "FROM people JOIN managers "
            "ON people.person_id = managers.person_id JOIN boss "
            "ON managers.person_id = boss.boss_id ORDER BY people.person_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_deferred.py

示例9: test_load_only_subclass_and_superclass_bound

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def test_load_only_subclass_and_superclass_bound(self):
        s = Session()
        q = (
            s.query(Boss)
            .order_by(Person.person_id)
            .options(Load(Boss).load_only("status", "manager_name"))
        )
        self.assert_compile(
            q,
            "SELECT managers.person_id AS managers_person_id, "
            "people.person_id AS people_person_id, "
            "people.type AS people_type, "
            "managers.status AS managers_status, "
            "managers.manager_name AS managers_manager_name "
            "FROM people JOIN managers "
            "ON people.person_id = managers.person_id JOIN boss "
            "ON managers.person_id = boss.boss_id ORDER BY people.person_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_deferred.py

示例10: test_load_only_alias_subclass_bound

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def test_load_only_alias_subclass_bound(self):
        s = Session()
        m1 = aliased(Manager, flat=True)
        q = (
            s.query(m1)
            .order_by(m1.person_id)
            .options(Load(m1).load_only("status", "manager_name"))
        )
        self.assert_compile(
            q,
            "SELECT managers_1.person_id AS managers_1_person_id, "
            "people_1.person_id AS people_1_person_id, "
            "people_1.type AS people_1_type, "
            "managers_1.status AS managers_1_status, "
            "managers_1.manager_name AS managers_1_manager_name "
            "FROM people AS people_1 JOIN managers AS "
            "managers_1 ON people_1.person_id = managers_1.person_id "
            "ORDER BY managers_1.person_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_deferred.py

示例11: test_load_only_subclass_from_relationship

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def test_load_only_subclass_from_relationship(self):
        s = Session()
        q = (
            s.query(Company)
            .join(Company.managers)
            .options(
                contains_eager(Company.managers).load_only(
                    "status", "manager_name"
                )
            )
        )
        self.assert_compile(
            q,
            "SELECT companies.company_id AS companies_company_id, "
            "companies.name AS companies_name, "
            "managers.person_id AS managers_person_id, "
            "people.person_id AS people_person_id, "
            "people.type AS people_type, "
            "managers.status AS managers_status, "
            "managers.manager_name AS managers_manager_name "
            "FROM companies JOIN (people JOIN managers ON people.person_id = "
            "managers.person_id) ON companies.company_id = people.company_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_deferred.py

示例12: test_load_only_subclass_from_relationship_bound

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def test_load_only_subclass_from_relationship_bound(self):
        s = Session()
        q = (
            s.query(Company)
            .join(Company.managers)
            .options(
                Load(Company)
                .contains_eager(Company.managers)
                .load_only("status", "manager_name")
            )
        )
        self.assert_compile(
            q,
            "SELECT companies.company_id AS companies_company_id, "
            "companies.name AS companies_name, "
            "managers.person_id AS managers_person_id, "
            "people.person_id AS people_person_id, "
            "people.type AS people_type, "
            "managers.status AS managers_status, "
            "managers.manager_name AS managers_manager_name "
            "FROM companies JOIN (people JOIN managers ON people.person_id = "
            "managers.person_id) ON companies.company_id = people.company_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_deferred.py

示例13: test_load_only_subclass_of_type

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def test_load_only_subclass_of_type(self):
        s = Session()
        q = s.query(Company).options(
            joinedload(Company.employees.of_type(Manager)).load_only("status")
        )
        self.assert_compile(
            q,
            "SELECT companies.company_id AS companies_company_id, "
            "companies.name AS companies_name, "
            "anon_1.people_person_id AS anon_1_people_person_id, "
            "anon_1.people_type AS anon_1_people_type, "
            "anon_1.managers_person_id AS anon_1_managers_person_id, "
            "anon_1.managers_status AS anon_1_managers_status "
            "FROM companies LEFT OUTER JOIN "
            "(SELECT people.person_id AS people_person_id, "
            "people.company_id AS people_company_id, "
            "people.name AS people_name, people.type AS people_type, "
            "managers.person_id AS managers_person_id, "
            "managers.status AS managers_status, "
            "managers.manager_name AS managers_manager_name "
            "FROM people LEFT OUTER JOIN managers "
            "ON people.person_id = managers.person_id) AS anon_1 "
            "ON companies.company_id = anon_1.people_company_id "
            "ORDER BY anon_1.people_person_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:27,代码来源:test_deferred.py

示例14: test_load_only_from_with_polymorphic

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def test_load_only_from_with_polymorphic(self):
        s = Session()

        wp = with_polymorphic(Person, [Manager], flat=True)

        assert_raises_message(
            sa.exc.ArgumentError,
            'Mapped attribute "Manager.status" does not apply to any of the '
            "root entities in this query, e.g. "
            r"with_polymorphic\(Person, \[Manager\]\).",
            s.query(wp).options(load_only(Manager.status))._compile_context,
        )

        q = s.query(wp).options(load_only(wp.Manager.status))
        self.assert_compile(
            q,
            "SELECT people_1.person_id AS people_1_person_id, "
            "people_1.type AS people_1_type, "
            "managers_1.person_id AS managers_1_person_id, "
            "managers_1.status AS managers_1_status "
            "FROM people AS people_1 "
            "LEFT OUTER JOIN managers AS managers_1 "
            "ON people_1.person_id = managers_1.person_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_deferred.py

示例15: test_joinedload_defered_pk_limit_o2m

# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import load_only [as 别名]
def test_joinedload_defered_pk_limit_o2m(self):
        Parent = self.classes.Parent

        s = Session()

        self.assert_compile(
            s.query(Parent)
            .options(load_only("data"), joinedload(Parent.o2mchild))
            .limit(10),
            "SELECT anon_1.parent_id AS anon_1_parent_id, "
            "anon_1.parent_data AS anon_1_parent_data, "
            "anon_1.parent_arb AS anon_1_parent_arb, "
            "o2mchild_1.id AS o2mchild_1_id, "
            "o2mchild_1.parent_id AS o2mchild_1_parent_id "
            "FROM (SELECT parent.id AS parent_id, parent.data AS parent_data, "
            "parent.arb AS parent_arb FROM parent LIMIT :param_1) AS anon_1 "
            "LEFT OUTER JOIN o2mchild AS o2mchild_1 "
            "ON anon_1.parent_arb = o2mchild_1.parent_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_eager_relations.py


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