Python ORM 框架:Pony ORM
jopen
10年前
Pony是一个非常酷和新的 Python ORM ,它能够让你使用Python generators来查询一个数据库。这些generators然后会转成高效的SQL。
语法:
select(c for c in Customer if sum(c.orders.price) > 1000)
翻译成 SQL 后的效果:
SELECT "c"."id" FROM "Customer" "c" LEFT JOIN "Order" "order-1" ON "c"."id" = "order-1"."customer" GROUP BY "c"."id" HAVING coalesce(SUM("order-1"."total_price"), 0) > 1000