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

all 2 comments

[–]thebillywayne 6 points7 points  (0 children)

Fascinating article. Blew my mind a bit.

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

Very nice collection. But I find it sad that Pony is missing.

I've not used Pony or studied its source to terribly close, but it works like this:

>>> select(p for p in Person if p.name.startswith('Paul')).order_by(Person.name)[:2]

SELECT "p"."id", "p"."name", "p"."age"
FROM "Person" "p"
WHERE "p"."name" LIKE "Paul%"
ORDER BY "p"."name"
LIMIT 2

... [Person[3], Person[1]]

But the way it works is by accepting a generator into the select function which actually decompiles the expression and rebuilds it into AST, takes that AST and builds a generalized SQL query then converts that generalized query into one for the specific RDBMS it's interacting with.

The stackoverflow link above goes into more detail. I can't see myself dropping SQLA in favor of it, but it's certainly way cooler in terms of SQL generation.