On 02/08/2017 05:31 PM, Shane Carey wrote:
This is an artificial example but it would help my application become
more modular if I could pass a Query object to my session.
I see in the docs it says "|Query|
<http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query>
objects
are normally initially generated using the |query()|
<http://docs.sqlalchemy.org/en/latest/orm/session_api.html#sqlalchemy.orm.session.Session.query>
method
of |Session|
<http://docs.sqlalchemy.org/en/latest/orm/session_api.html#sqlalchemy.orm.session.Session>.
For a full walkthrough of |Query|
<http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query>
usage,
see the Object Relational Tutorial
<http://docs.sqlalchemy.org/en/latest/orm/tutorial.html>.", which makes
me think this is possible.
class Thing(Base):
__tablename__ = 'thing'
id = Column(Integer, primary_key=True)
e = create_engine('...')
s = Session(engine)
q = Query(Thing).filter(Thing.id == 5)
r = s.query(q).one() # How do I do this? if at all?
You can definitely make a Query directly with the constructor as you're
doing, and then to associate with a Session you simply say r =
q.with_session(session).one().
--
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 sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.