Prints out a list of all the bloggers registered on the platform ordered by the number of posts they've made.
The query itself is an ORM hack that works. I don't know if it's good as a SQL query or not, but for checking up on the two users currently registered on commit--blog it's just fine. Here is the SQL it generates
SELECT blogger.id AS blogger_id, blogger.gh_id AS blogger_gh_id, blogger.username AS blogger_username, blogger.name AS blogger_name, blogger.avatar_url AS blogger_avatar_url, blogger.access_token AS blogger_access_token FROM blogger ORDER BY (SELECT count(blogger.id = commit_post.blogger_id) AS count_1 FROM commit_post)
ORDER BY (SELECT count... makes me nervous; it seems like it's doing a lot of work. Then again the python code felt like it would be a lot of work too:
bloggers = Blogger.query \ .order_by(db.session.query( func.count(Blogger.commit_posts)))
I'd like to spend some more time learning and writing SQL queries. Not that I ever work with enough data for my fumbling ORM hacks to matter, but I'd like to have a more clear picture of what is going on. Maybe some day I'll have enough data to play with for it to matter.
My impression of
SQLAlchemy is that, given knowledge of how to write good queries, it makes expressing them pythonic and doesn't get in your way. Not that I have experience to know, but for now that's why I'm still using it, given how easy it makes getting data in and out.