Rinq?

Anyone else interested in creating a RINQ?

See:

http://graffie.wordpress.com/2008/03/12/rinq-concept-of-a-ruby-integr

http://rubyforge.org/frs/download.php/26198/BRUG-10-03-2007.pdf

I need something a long these lines for doing SQL queries, but it
would be great to take it one step further toward a general purpose
LINQ-like library.

I have too much on plate right now to pursue this by myself, but I be
happy to help out anyone who wants to run with it.

T.

From: Trans [mailto:[email protected]]

http://graffie.wordpress.com/2008/03/12/rinq-concept-of-a-ruby-integr

http://rubyforge.org/frs/download.php/26198/BRUG-10-03-2007.pdf

very nice. but still very sql-ish.
i like ruby keywords better.

eg, from this

customernames = customers.
qwhere {|c| c.address.city == “London”}.
qselect {|c| {:firstname => c.firstname,
:lastname => c.lastname}}.
qorderby {|c| c.lastname}

i prefer this instead

customernames = customers.
select {|c| c.address.city == “London”}.
collect{|c| [c.firstname,c.lastname]}.
sort_by{|c| c.lastname}

this way i think in ruby all the way.

kind regards -botp

On Oct 7, 12:36 am, Peña, Botp [email protected] wrote:

          collect{|c| [c.firstname,c.lastname]}.
          sort_by{|c| c.lastname}

Interesting. I tried translating this idea to a more complex example.
Given pseudo-LINQ like:

r = query do
from :c => :customer, :a => :account, :b => :bank
select b.name
where (( c.firstname == first1 ) |
( c.firstname == first2 ) ) &
( c.lastname =~ last ) &
( a.owner == c ) &
( a.bank == b )
end

How would you work that? I played with it a bit and thought of:

 customers = from(:customers)

 a = from(:account)
 b = from(:bank)

 r = customers.select { |c|
   (c.firstname == first1 ||
    c.firstname == first2) &&
    c.lastname =~ last &&
    a.owner == c &&
    a.bank == b
 }.collect { |c| c.name }

I generally like the idea, albeit the modus operandi of LINQ has been
to reflect as much as possible the original domain language (sql, xml,
etc.) in the target language. Nonetheless, I can see the advantage of
expressing queries in native Ruby instead, and having that translated
to the domain language. But is Ruby ultimately expressive enough? We
may end up adding enough new syntax (eg. inner and outer joins), that
it will largely overshadow the native syntax anyway.

T.

On Oct 7, 5:11 am, Peña, Botp [email protected] wrote:

end

   end

Ah, I see. Ok, then even a little more Rubyish:

r = select(customer, account, bank) do |c,a,b|
(( c.firstname == first1 ) ||
( c.firstname == first2 )) &&
( c.lastname =~ last ) &&
( a.owner == c ) &&
( a.bank == b )
end.
collect(customer){ |b| b.name }

#…

But is Ruby ultimately expressive enough? We

may end up adding enough new syntax

i think ruby syntax is more than enough (imho). In a way, i’d like to think like active records when it comes to databases (in mfowler’s sense, not rails) and use ruby to implem.

How does Fowler’s approach differ from Rails? I didn’t know there was
an essential distinction.

T.

Isn’t this basically what Ambition is?

http://ambition.rubyforge.org/

–Jeremy

On Tue, Oct 7, 2008 at 9:31 AM, Trans [email protected] wrote:

( c.lastname =~ last ) &

            ( a.owner == c ) &
 ( a.owner == c ) &&

How does Fowler’s approach differ from Rails? I didn’t know there was
an essential distinction.

T.


http://jeremymcanally.com/
http://entp.com/

My books:

http://humblelittlerubybook.com/ (FREE!)

From: Trans [mailto:[email protected]]
#…

r = query do

from :c => :customer, :a => :account, :b => :bank

select b.name

where (( c.firstname == first1 ) |

( c.firstname == first2 ) ) &

( c.lastname =~ last ) &

( a.owner == c ) &

( a.bank == b )

end

try

r = query(customer, account, bank) do |c,a,b|
select (( c.firstname == first1 ) |
( c.firstname == first2 ) ) &
( c.lastname =~ last ) &
( a.owner == c ) &
( a.bank == b ) .
collect b.name
end

#…

But is Ruby ultimately expressive enough? We

may end up adding enough new syntax

i think ruby syntax is more than enough (imho). In a way, i’d like to
think like active records when it comes to databases (in mfowler’s
sense, not rails) and use ruby to implem.

kind regards -botp

On Oct 7, 12:29 pm, “Jeremy McAnally” [email protected]
wrote:

Isn’t this basically what Ambition is?

http://ambition.rubyforge.org/

Hey, nice. That’s pretty close to botp’s thoughts.

Though again, I see potential limitations in this approach, eg. how to
select from multiple tables?

Also I’m a bit surprised to see that it uses ParseTree --that seems
like overkill on the implementation side of things. How stable is
Ambition at this point? If I were to use it for my project, I would
need to a) maybe create a DBI adapter and 2) add support for ‘insert’
and ‘update’ (along side ‘select’, ‘slice’ and ‘sort’). Possible?

T.

On Oct 7, 12:17 pm, Trans [email protected] wrote:

Also I’m a bit surprised to see that it uses ParseTree --that seems
like overkill on the implementation side of things.

I believe its use of ParseTree is because != and !~ are not methods in
Ruby 1.8. Without being able to define != separately from ==, having
them translate to different things is a difficult task.

I think I have unsubscribed to this list twice, and it won’t stop
coming!

-Brian