Trans
12/6/2006 4:03:00 PM
Victor "Zverok" Shepelev wrote:
> Hi all.
>
> Random idea, just for fun - using "list comprehensions" for SQL queries
> generation.
>
> employees = Table.new(:id, :name, :sec_name, :salary, :age)
>
> employees.select{|e| e.name == 'John' && e.salary > 50}.sort_by{|e|
> e.age}[2,10]
>
> #generates "select * from Employees where name = 'John' and salary > 50
> order by age limit 2,10"
>
> employees.select{|e| e.salary < 150}.count
>
> #generates "select count(*) from Employees where salary < 150
>
> Something like this. (I still don't know, how to limit selected columns in
> obvious way)
>
> And even more complex:
>
> employees = Table.new(:id, :name, :sec_name, :salary, :age)
> positions = Table.new(:id, :employee_id, :position_name)
>
> (employees + positions).select{|e, p| e.id == p.employee_id}
>
> #generates "select * from Employees, Positions where Employees.id ==
> Positions.employee_id"
>
> Idea is completely stolen from Phil Wadler's Links[1] language.
> Also MS's LINQ and ruby's Mongoose DB seems to do something like this.
>
> But the realization of above seems to be interesting task (for RubyQuiz, may
> be?)
>
> Thanks for your patience. And sorry me my English.
I think Og can already do this, more or less.
T.