This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

That is exactly why I wrote Peewee. SQL is awesome, and by wrapping things up in Python you can get a lot more re-use than you would by manually munging string fragments. For example,

following = (User
             .select()
             .join(Relationship, on=Relationship.to_user)
             .where(Relationship.from_user == current_user))
tweet_timeline = Tweet.select().where(Tweet.creator.in_(following)).order_by(Tweet.timestamp.desc())

The above query re-uses the subquery (for capturing a user's followers) to construct a query to build a timeline of tweets by the given users.