[lnkForumImage]
TotalShareware - Download Free Software

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


 

Trans

10/6/2008 7:35:00 PM

Anyone else interested in creating a RINQ?

See:

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

http://rubyforge.org/frs/download.php/26198/BRUG-10-0...

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.

8 Answers

Peña, Botp

10/7/2008 4:37:00 AM

0

From: Trans [mailto:transfire@gmail.com]=20
# =
http://graffie.wordpress.com/2008/03/12/rinq-concept-of-a-r......
#=20
# http://rubyforge.org/frs/download.php/26198/BRUG-10-0...
#=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

Trans

10/7/2008 6:01:00 AM

0



On Oct 7, 12:36=A0am, Pe=F1a, Botp <b...@delmonte-phil.com> wrote:
> From: Trans [mailto:transf...@gmail.com]
> #http://graffie.wordpress.com/2008/03/12/rinq-concept-of-a-r......
> #
> # =A0http://rubyforge.org/frs/download.php/26198/BRUG-10-0...
> #
>
> 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.

Peña, Botp

10/7/2008 9:11:00 AM

0

From: Trans [mailto:transfire@gmail.com]=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

Trans

10/7/2008 2:32:00 PM

0



On Oct 7, 5:11=A0am, Pe=F1a, Botp <b...@delmonte-phil.com> wrote:
> From: Trans [mailto:transf...@gmail.com]
> #...
> # =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.

Jeremy McAnally

10/7/2008 4:29:00 PM

0

Isn't this basically what Ambition is?

http://ambition.ruby...

--Jeremy

On Tue, Oct 7, 2008 at 9:31 AM, Trans <transfire@gmail.com> wrote:
>
>
> On Oct 7, 5:11 am, Pe=F1a, Botp <b...@delmonte-phil.com> wrote:
>> From: Trans [mailto:transf...@gmail.com]
>> #...
>> # 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://jeremymca...
http:/...
http://omgb...

My books:
http://manning.com...
http://humblelittlerub... (FREE!)

Trans

10/7/2008 5:18:00 PM

0



On Oct 7, 12:29=A0pm, "Jeremy McAnally" <jeremymcana...@gmail.com>
wrote:
> Isn't this basically what Ambition is?
>
> =A0 =A0http://ambition.ruby...

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.

Yossef Mendelssohn

10/7/2008 6:42:00 PM

0

On Oct 7, 12:17=A0pm, Trans <transf...@gmail.com> 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 !=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.

--
-yossef

brian

10/7/2008 7:19:00 PM

0

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

-Brian