On Mon, Jan 22, 2018 at 9:45 AM, Joe Biggert <[email protected]> wrote:
> Ah crap, thanks for the verbose response. I got to the part where I forgot to 
> mention what we're using for the db - Postgres w/ psycopg. Sorry for leaving 
> out a vital piece. Still analyzing the rest of the response!
>


oh, lest I forget since I spent weeks on it, we *do* have collection
eager loading with yield_per if you use the new "selectin" loader.
that is, change joinedload() to selectin().  if we have ten rows
primary entities:

s = Session(e)
s.add_all([A(bs=[B() for i in range(10)]) for j in range(10)])
s.commit()

q = s.query(A).options(selectinload(A.bs))

for a in q.yield_per(5):
    print a


selectin will do the eager loads individually for each yielded group:

SELECT a.id AS a_id FROM a

(first yield)

SELECT a_1.id AS a_1_id, b.id AS b_id, b.a_id AS b_a_id
FROM a AS a_1 JOIN b ON a_1.id = b.a_id
WHERE a_1.id IN (?, ?, ?, ?, ?) ORDER BY a_1.id
2018-01-22 09:54:28,387 INFO sqlalchemy.engine.base.Engine (1, 2, 3, 4, 5)

A(bs=[B(id=1), B(id=2), B(id=3), B(id=4), B(id=5), B(id=6), B(id=7),
B(id=8), B(id=9), B(id=10)])
A(bs=[B(id=11), B(id=12), B(id=13), B(id=14), B(id=15), B(id=16),
B(id=17), B(id=18), B(id=19), B(id=20)])
A(bs=[B(id=21), B(id=22), B(id=23), B(id=24), B(id=25), B(id=26),
B(id=27), B(id=28), B(id=29), B(id=30)])
A(bs=[B(id=31), B(id=32), B(id=33), B(id=34), B(id=35), B(id=36),
B(id=37), B(id=38), B(id=39), B(id=40)])
A(bs=[B(id=41), B(id=42), B(id=43), B(id=44), B(id=45), B(id=46),
B(id=47), B(id=48), B(id=49), B(id=50)])

(next yield)

SELECT a_1.id AS a_1_id, b.id AS b_id, b.a_id AS b_a_id
FROM a AS a_1 JOIN b ON a_1.id = b.a_id
WHERE a_1.id IN (?, ?, ?, ?, ?) ORDER BY a_1.id
2018-01-22 09:54:28,390 INFO sqlalchemy.engine.base.Engine (6, 7, 8, 9, 10)

A(bs=[B(id=51), B(id=52), B(id=53), B(id=54), B(id=55), B(id=56),
B(id=57), B(id=58), B(id=59), B(id=60)])
A(bs=[B(id=61), B(id=62), B(id=63), B(id=64), B(id=65), B(id=66),
B(id=67), B(id=68), B(id=69), B(id=70)])
A(bs=[B(id=71), B(id=72), B(id=73), B(id=74), B(id=75), B(id=76),
B(id=77), B(id=78), B(id=79), B(id=80)])
A(bs=[B(id=81), B(id=82), B(id=83), B(id=84), B(id=85), B(id=86),
B(id=87), B(id=88), B(id=89), B(id=90)])
A(bs=[B(id=91), B(id=92), B(id=93), B(id=94), B(id=95), B(id=96),
B(id=97), B(id=98), B(id=99), B(id=100)])


so, that might make life a lot easier for you.






> Thanks again.
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and 
> Verifiable Example.  See  http://stackoverflow.com/help/mcve for a full 
> description.
> ---
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to