Request objects can be considered as as-is iterators. SQL will be launched after you start using data from the query iterator. Example:
for author in session.query(Author).filter(Author.queried==0): print "Processing: ", author
Your question uses the word "endlessly," so a word of caution. SQL is not an event handling API; you cannot just execute a query that runs forever and splashes out every new row as it is added to the table. I would like it to be possible, but it is not.
If you intend to detect new rows, you will have to regularly poll the same query and create an indicator in your data model that allows you to tell you which rows are new. It seems you present this now with a queried column. In this case, in the for loop above you can set author.queried = 1 and session.add(author) . But you cannot session.commit() inside the loop.
source share