RINQ?

P

Peña, Botp

From: Trans [mailto:[email protected]]=20
# =
http://graffie.wordpress.com/2008/03/12/rinq-concept-of-a-ruby-integr...
#=20
# http://rubyforge.org/frs/download.php/26198/BRUG-10-03-2007.pdf
#=20

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

eg, from this

customernames =3D customers.
qwhere {|c| c.address.city =3D=3D "London"}.
qselect {|c| {:firstname =3D> c.firstname,
:lastname =3D> c.lastname}}.
qorderby {|c| c.lastname}

i prefer this instead

customernames =3D customers.
select {|c| c.address.city =3D=3D "London"}.
collect{|c| [c.firstname,c.lastname]}.
sort_by{|c| c.lastname}

this way i think in ruby all the way.

kind regards -botp
 
T

Trans

From: Trans [mailto:[email protected]]
#http://graffie.wordpress.com/2008/03/12/rinq-concept-of-a-ruby-integr...
#
# =A0http://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 =3D customers.
=A0 =A0 =A0 =A0 =A0 =A0 =A0 qwhere {|c| c.address.city =3D=3D "London"}.
=A0 =A0 =A0 =A0 =A0 =A0 =A0 qselect =A0{|c| {:firstname =3D> c.firstname,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 :lastname =A0=3D> c.lastname}}.
=A0 =A0 =A0 =A0 =A0 =A0 =A0 qorderby {|c| c.lastname}

i prefer this instead

customernames =3D customers.
=A0 =A0 =A0 =A0 =A0 =A0 =A0 select {|c| c.address.city =3D=3D "London"}.
=A0 =A0 =A0 =A0 =A0 =A0 =A0 collect{|c| [c.firstname,c.lastname]}.
=A0 =A0 =A0 =A0 =A0 =A0 =A0 sort_by{|c| c.lastname}

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

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

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

customers =3D from:)customers)

a =3D from:)account)
b =3D from:)bank)

r =3D customers.select { |c|
(c.firstname =3D=3D first1 ||
c.firstname =3D=3D first2) &&
c.lastname =3D~ last &&
a.owner =3D=3D c &&
a.bank =3D=3D 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.
 
P

Peña, Botp

From: Trans [mailto:[email protected]]=20
#...
# r =3D query do
# from :c =3D> :customer, :a =3D> :account, :b =3D> :bank
# select b.name
# where (( c.firstname =3D=3D first1 ) |
# ( c.firstname =3D=3D first2 ) ) &
# ( c.lastname =3D~ last ) &
# ( a.owner =3D=3D c ) &
# ( a.bank =3D=3D b )
# end

try

r =3D query(customer, account, bank) do |c,a,b|
select (( c.firstname =3D=3D first1 ) |
( c.firstname =3D=3D first2 ) ) &
( c.lastname =3D~ last ) &
( a.owner =3D=3D c ) &
( a.bank =3D=3D 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
 
T

Trans

From: Trans [mailto:[email protected]]
#...
# =A0 r =3D query do
# =A0 =A0 =A0 =A0 from :c =3D> :customer, :a =3D> :account, :b =3D> :bank
# =A0 =A0 =A0 =A0 select b.name
# =A0 =A0 =A0 =A0 where (( c.firstname =3D=3D first1 ) |
# =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0( c.firstname =3D=3D first2 ) ) &
# =A0 =A0 =A0 =A0 =A0 =A0 =A0 ( c.lastname =3D~ last ) &
# =A0 =A0 =A0 =A0 =A0 =A0 =A0 ( a.owner =3D=3D c ) &
# =A0 =A0 =A0 =A0 =A0 =A0 =A0 ( a.bank =3D=3D b )
# =A0 end

try

=A0 =A0r =3D query(customer, account, bank) =A0do |c,a,b|
=A0 =A0 =A0 =A0 =A0select (( c.firstname =3D=3D first1 ) |
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ( c.firstname =3D=3D first2 ) ) &
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ( c.lastname =3D~ last ) &
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ( a.owner =3D=3D c ) &
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ( a.bank =3D=3D b ) .
=A0 =A0 =A0 =A0 =A0collect b.name
=A0 =A0 =A0 =A0end

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

r =3D select(customer, account, bank) do |c,a,b|
(( c.firstname =3D=3D first1 ) ||
( c.firstname =3D=3D first2 )) &&
( c.lastname =3D~ last ) &&
( a.owner =3D=3D c ) &&
( a.bank =3D=3D 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 thi=
nk 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.
 
J

Jeremy McAnally

Isn't this basically what Ambition is?

http://ambition.rubyforge.org/

--Jeremy

From: Trans [mailto:[email protected]]
#...
# r =3D query do
# from :c =3D> :customer, :a =3D> :account, :b =3D> :bank
# select b.name
# where (( c.firstname =3D=3D first1 ) |
# ( c.firstname =3D=3D first2 ) ) &
# ( c.lastname =3D~ last ) &
# ( a.owner =3D=3D c ) &
# ( a.bank =3D=3D b )
# end

try

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

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

r =3D select(customer, account, bank) do |c,a,b|
(( c.firstname =3D=3D first1 ) ||
( c.firstname =3D=3D first2 )) &&
( c.lastname =3D~ last ) &&
( a.owner =3D=3D c ) &&
( a.bank =3D=3D 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 th=
ink 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.



--=20
http://jeremymcanally.com/
http://entp.com/
http://omgbloglol.com

My books:
http://manning.com/mcanally/
http://humblelittlerubybook.com/ (FREE!)
 
T

Trans

Isn't this basically what Ambition is?

=A0 =A0http://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.
 
Y

Yossef Mendelssohn

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 !=3D and !~ are not methods in
Ruby 1.8. Without being able to define !=3D separately from =3D=3D, having
them translate to different things is a difficult task.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,199
Messages
2,571,045
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top