FWIW, I often make queries that map to a 'logical object' like this one 
(e.g. "leaderboard") that have a lot of reads as a View in the database, 
then create a separate SqlAlchemy ORM object for it and have every relation 
to/from that marked as view_only. This has nothing to do with writing the 
query in SqlAlchemy (you'll be writing much more complex ones sooner, and 
with ease), and more with managing that type of info and keeping the 
queries optimized on the database management layer. So I tied an onion to 
my belt, which was the style at the time.



On Thursday, May 23, 2019 at 3:52:00 AM UTC-4, Michael P. McDonnell wrote:

> Hi Everybody! (Hi Dr. Nick!)
>
> I am creating a game for the work I'm doing - and while I didn't create 
> the schema - I certainly have to program against it.
> What I have is a PERSON, a GAME, a PLAY and a collection of RESULT
>
> What I'd like to do is call the "leaderboard" member of my GAME class - 
> and get the read only results from the following query:
> SELECT
> person.display_name AS display_name,
> COUNT(result.task_id) AS total_tasks_completed,
> SUM(
> (result.finish_dttm - result.start_dttm) - result.validation_time
> ) AS total_time
> FROM
> result
> JOIN play ON (result.play_id = play.id)
> JOIN person ON (play.person_id = person.id)
> JOIN game ON (play.game_id = game.id)
> WHERE game.id = 'fc8dd2e5-ecdb-47f4-811e-3c01ee9f4176'
> GROUP BY person.display_name



-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/06bfe40f-30f9-4580-b2af-87e43ab552ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to