Forum: Ruby RINQ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2008-10-06 21:37
(Received via mailing list)
Anyone else interested in creating a RINQ?

See:

  http://graffie.wordpress.com/2008/03/12/rinq-conce......

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

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.
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Peña, Botp (Guest)
on 2008-10-07 06:39
(Received via mailing list)
From: Trans [mailto:transfire@gmail.com]
#
http://graffie.wordpress.com/2008/03/12/rinq-conce......
#
#   http://rubyforge.org/frs/download.php/26198/BRUG-1...
#

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
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2008-10-07 08:06
(Received via mailing list)
On Oct 7, 12:36 am, Peña, Botp <b...@delmonte-phil.com> 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.
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Peña, Botp (Guest)
on 2008-10-07 11:14
(Received via mailing list)
From: Trans [mailto:transfire@gmail.com]
#...
#   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
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2008-10-07 17:16
(Received via mailing list)
On Oct 7, 5:11 am, Peña, Botp <b...@delmonte-phil.com> 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.
6d3c187a8b3ef53b08e3e7e8572c4fea?d=identicon&s=25 Jeremy McAnally (Guest)
on 2008-10-07 18:32
(Received via mailing list)
Isn't this basically what Ambition is?

    http://ambition.rubyforge.org/

--Jeremy

On Tue, Oct 7, 2008 at 9:31 AM, Trans <transfire@gmail.com> 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/
http://omgbloglol.com

My books:
http://manning.com/mcanally/
http://humblelittlerubybook.com/ (FREE!)
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2008-10-07 19:20
(Received via mailing list)
On Oct 7, 12:29 pm, "Jeremy McAnally" <jeremymcana...@gmail.com>
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.
B1b1d33e0655e841d4fd8467359c58d0?d=identicon&s=25 Yossef Mendelssohn (Guest)
on 2008-10-07 20:44
(Received via mailing list)
On Oct 7, 12:17 pm, 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 != 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.
D8e709fab0201534f93d102f74740a52?d=identicon&s=25 Brian Anderson (rakuda)
on 2008-10-07 21:21
(Received via mailing list)
I think I have unsubscribed to this list twice, and it won't stop
coming!

-Brian
This topic is locked and can not be replied to.