On Thursday, January 5, 2017 at 8:34:52 PM UTC-5, Daniel Kraus wrote:
>
> The use-case is that I have a big model with lots of complex
>
> relationships but 90% of the time I don't need the data from those.
>

If I'm reading your question correctly, most of what sqlalchemy does (and 
excels at) is specifically keeping people from doing what you're trying to 
do.  It seems like you're trying to avoid all the work that is done to 
ensure data integrity across sessions and transactions.  (Which is a common 
need)

Read up on the `merge` session 
method 
(http://docs.sqlalchemy.org/en/latest/orm/session_state_management.html#merging)
 
 The dogpile caching section is largely based on that (though goes beyond 
it).   

You would do something like this:

    user = User(**userdata) 
    user = session.merge(user)

That will merge the user object into the session (and return the merged 
object).

You will run into problems if your cached data is incomplete though -- 
AFAIK, there is no way to tell sqlalchemy that you've only loaded data for 
certain columns.  If you don't populate all the columns in your cache, but 
have it in the db, I have no idea how to get that info from the db.

-- 
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