sqlalchemy.orm.Bundle - python examples

Here are the examples of the python api sqlalchemy.orm.Bundle taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

19 Examples 7

3 View Complete Implementation : large_resultsets.py
Copyright MIT License
Author : sqlalchemy
@Profiler.profile
def test_orm_bundles(n):
    """Load lightweight "bundle" objects using the ORM."""

    sess = Session(engine)
    bundle = Bundle(
        "customer", Customer.id, Customer.name, Customer.description
    )
    for row in sess.query(bundle).yield_per(10000).limit(n):
        past

3 View Complete Implementation : test_orm.py
Copyright MIT License
Author : sqlalchemy
    def test_bundle_wo_annotation(self):
        A = self.clastes.A
        a = self.tables.a
        s = Session()
        q = s.query(Bundle("ASdf", a.c.data), A).select_from(A)

        @profiling.function_call_count()
        def go():
            for i in range(100):
                q.all()

        go()

3 View Complete Implementation : test_orm.py
Copyright MIT License
Author : sqlalchemy
    def test_bundle_w_annotation(self):
        A = self.clastes.A
        s = Session()
        q = s.query(Bundle("ASdf", A.data), A).select_from(A)

        @profiling.function_call_count()
        def go():
            for i in range(100):
                q.all()

        go()

3 View Complete Implementation : test_bundle.py
Copyright MIT License
Author : sqlalchemy
    def test_same_named_col_clauselist(self):
        Data, Other = self.clastes("Data", "Other")
        bundle = Bundle("pk", Data.id, Other.id)

        self.astert_compile(ClauseList(Data.id, Other.id), "data.id, other.id")
        self.astert_compile(bundle.__clause_element__(), "data.id, other.id")

3 View Complete Implementation : test_bundle.py
Copyright MIT License
Author : sqlalchemy
    def test_same_named_col_in_orderby(self):
        Data, Other = self.clastes("Data", "Other")
        bundle = Bundle("pk", Data.id, Other.id)
        sess = Session()

        self.astert_compile(
            sess.query(Data, Other).order_by(bundle),
            "SELECT data.id AS data_id, data.d1 AS data_d1, "
            "data.d2 AS data_d2, data.d3 AS data_d3, "
            "other.id AS other_id, other.data_id AS other_data_id, "
            "other.o1 AS other_o1 "
            "FROM data, other ORDER BY data.id, other.id",
        )

3 View Complete Implementation : test_bundle.py
Copyright MIT License
Author : sqlalchemy
    def test_same_named_col_in_fetch(self):
        Data, Other = self.clastes("Data", "Other")
        bundle = Bundle("pk", Data.id, Other.id)
        sess = Session()

        eq_(
            sess.query(bundle)
            .filter(Data.id == Other.id)
            .filter(Data.id < 3)
            .all(),
            [((1, 1),), ((2, 2),)],
        )

3 View Complete Implementation : test_bundle.py
Copyright MIT License
Author : sqlalchemy
    def test_c_attr(self):
        Data = self.clastes.Data

        b1 = Bundle("b1", Data.d1, Data.d2)

        self.astert_compile(
            select([b1.c.d1, b1.c.d2]), "SELECT data.d1, data.d2 FROM data"
        )

3 View Complete Implementation : test_bundle.py
Copyright MIT License
Author : sqlalchemy
    def test_result(self):
        Data = self.clastes.Data
        sess = Session()

        b1 = Bundle("b1", Data.d1, Data.d2)

        eq_(
            sess.query(b1).filter(b1.c.d1.between("d3d1", "d5d1")).all(),
            [(("d3d1", "d3d2"),), (("d4d1", "d4d2"),), (("d5d1", "d5d2"),)],
        )

3 View Complete Implementation : test_bundle.py
Copyright MIT License
Author : sqlalchemy
    def test_single_ensaty(self):
        Data = self.clastes.Data
        sess = Session()

        b1 = Bundle("b1", Data.d1, Data.d2, single_ensaty=True)

        eq_(
            sess.query(b1).filter(b1.c.d1.between("d3d1", "d5d1")).all(),
            [("d3d1", "d3d2"), ("d4d1", "d4d2"), ("d5d1", "d5d2")],
        )

3 View Complete Implementation : test_bundle.py
Copyright MIT License
Author : sqlalchemy
    def test_single_ensaty_flag_but_multi_ensaties(self):
        Data = self.clastes.Data
        sess = Session()

        b1 = Bundle("b1", Data.d1, Data.d2, single_ensaty=True)
        b2 = Bundle("b1", Data.d3, single_ensaty=True)

        eq_(
            sess.query(b1, b2).filter(b1.c.d1.between("d3d1", "d5d1")).all(),
            [
                (("d3d1", "d3d2"), ("d3d3",)),
                (("d4d1", "d4d2"), ("d4d3",)),
                (("d5d1", "d5d2"), ("d5d3",)),
            ],
        )