It's really quite interesting that they build the queries from the AST. To contrast C# generates the Sql for Linq to Sql by building up an expression tree using the IQueryable interface.
This simplifies step one of the Pony ORM author's answer.
http://stackoverflow.com/questions/16115713/how-pony-orm-doe...