From: khaines@... Date: 2006-12-06T19:14:06+09:00 Subject: Re: Lisp comprehensions => SQL On Wed, 6 Dec 2006, Victor "Zverok" Shepelev wrote: >>> 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. Think about the syntax of it, though. From a ruby perspective, you call select(), then sort_by(), then [] Three separate method calls, and there is no way any of them can know which is the last one. So there's no way to assemble the SQL call you would like to see, where a single query is assembled to implement what is implied by those three separate method calls. To me, the logical thing is to have the select() call be the one that actually interacts with the database, and I am using "just Ruby" inside that select() block, and I know what I am getting back from each method call in the chain. Kirk Haines