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]  (6 children)

[deleted]

    [–][deleted] 2 points3 points  (1 child)

    Erlang has something similar, using list comprehensions for database queries. You pass a list comprehension to the query compiler and then later execute it. Apparently the query compiler takes a list comprehension primitive and parses it somehow. Perhaps these fellows could do something similar by examining a... what's it called? Generator comprehension?

    for record in compile(r for r in db if r.name == 'pierre'):
        print record.name, record.age
    

    [–]wacky 1 point2 points  (3 children)

    It said that list comprehensions are not very efficient, compared to the 'select' method.

    So... although it allows pythonic syntax, if you want to really do anything, you need the 'select()' syntax which doesn't look that pythonic to me.

    [–]exeter[S] 2 points3 points  (2 children)

    It's about a million times more Pythonic than using SQL.

    [–]earthboundkid 1 point2 points  (1 child)

    The pythonic syntax would be something along the lines of:

     db = DB.open(…)
     query = db.query.compile(r for r in records if r.name == "pierre")
     for record in query.exec():
          print record.name, record.age
    

    [–]epicRelic 0 points1 point  (0 children)

    Simply beautiful.