[PonyORM-list] Separating projection and filter in Query?

Tomislav Tustonic ttustonic at outlook.com
Thu Aug 14 00:52:21 UTC 2014


Hello First, thanks for fixing a bug with the lambda expressions and closures. Also, to_dict method is quite handy.I'm continuing with my exploration of the querying in Pony orm, and I have a following question/problem:Is it possible to separate a projection part from the filtering part of the query?For example I'd like to find only the names of the people older than 30 years, and have it all executed in the database query.Something like this: q = select(p.name for p in Person)   # 
q = q.filter(lambda p: p.age > 30) or, even better:q = select(p for p in Person)q1 = q.filter(lambda p: p.age > 30)q2= select(p.name for p in q1) none of these, obviously, don't work, but you get the idea.The closest I can get to this is to pick only the names from the q1, but in this case all the fields are retrieved from the database.The use for this is that I could have the same filtering logic (possibly complex, with quite a lot of predicates), but get different results (for example a list of key/value for a dropdown list and a larger set of attributes to show on some grid). So, is something like this possible, and if not, are you planning to add this feature? Thanks in advance, Tom
  		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20140814/c16cd4ff/attachment.html>


More information about the ponyorm-list mailing list