[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Lisp comprehensions => SQL

Victor 'Zverok' Shepelev

12/6/2006 8:10:00 AM

From: khaines@enigo.com [mailto:khaines@enigo.com]
Sent: Wednesday, December 06, 2006 3:19 AM
>On Wed, 6 Dec 2006, Victor "Zverok" Shepelev wrote:
>
>> #having
>> employees.select do |e|
>> sort_by(e.age)
>> limit(2,10)
>> (e.name == 'John') & (e.salary > 50)
>> end
>>
>> #proposal:
>>
>> employees.select{|e| (e.name == 'John') & (e.salary > 50)}.sort_by{|e|
>> e.age}[2..10]
>>
>> The latter is "just Ruby".
>>
>
>Actually, you could do that second one with Kansas. With the current
>Kansas, it'd be:
>
>dbh.select(:Employees) {|e| (e.name == 'John') & (e.salary >
>50)}.sort_by{|e| e.age}[2..10]
>
>The difference, though, is that it won't do all of that on the database.
>
>The database will do "select * from employees where e.name = 'John' and
>e.salary > 50" and then the results will be sorted by Ruby and the set
>extracted by Ruby.
>
This is predictable, but not very interesting.

v.


1 Answer

khaines

12/6/2006 10:14:00 AM

0