# Rinq?

**URL:** <https://www.ruby-forum.com/t/rinq/150280>\
**Category:** Ruby\
**Created:** [October 6, 2008, 9:37pm UTC](https://www.ruby-forum.com/t/rinq/150280 "2008-10-06T21:37:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [October 6, 2008, 9:37pm UTC](https://www.ruby-forum.com/t/rinq/150280/1 "2008-10-06T21:37:29Z")

</div>

Anyone else interested in creating a RINQ?

See:

[http://graffie.wordpress.com/2008/03/12/rinq-concept-of-a-ruby-integr](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](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.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [October 7, 2008, 6:39am UTC](https://www.ruby-forum.com/t/rinq/150280/2 "2008-10-07T06:39:26Z")

</div>

From: Trans [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# 

[http://graffie.wordpress.com/2008/03/12/rinq-concept-of-a-ruby-integr](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](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

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [October 7, 2008, 8:06am UTC](https://www.ruby-forum.com/t/rinq/150280/3 "2008-10-07T08:06:10Z")

</div>

On Oct 7, 12:36 am, Peña, Botp [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [October 7, 2008, 5:16pm UTC](https://www.ruby-forum.com/t/rinq/150280/4 "2008-10-07T17:16:31Z")

</div>

On Oct 7, 5:11 am, Peña, Botp [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [October 7, 2008, 6:32pm UTC](https://www.ruby-forum.com/t/rinq/150280/5 "2008-10-07T18:32:03Z")

</div>

Isn’t this basically what Ambition is?

```
http://ambition.rubyforge.org/

```

–Jeremy

On Tue, Oct 7, 2008 at 9:31 AM, Trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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://jeremymcanally.com/)  
[http://entp.com/](http://entp.com/)

> **[Omg GIFs | GIFDB.com](https://gifdb.com/omg)**
>
> Download Omg GIFs for Free on GifDB. More than 56 Omg Animated GIFs to download.

My books:

> **[Ruby in Practice](https://www.manning.com/books/ruby-in-practice)**
>
> Like Ruby itself, Ruby in Practice will make you more productive. The book shows you practical techniques and strategies for small projects and large-scale environments. A cookbook-style reference, it gives you concrete examples of systems...

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

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [October 7, 2008, 11:14am UTC](https://www.ruby-forum.com/t/rinq/150280/6 "2008-10-07T11:14:01Z")

</div>

From: Trans [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
#…

# 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

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [October 7, 2008, 7:20pm UTC](https://www.ruby-forum.com/t/rinq/150280/7 "2008-10-07T19:20:08Z")

</div>

On Oct 7, 12:29 pm, “Jeremy McAnally” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Isn’t this basically what Ambition is?
> 
> [http://ambition.rubyforge.org/](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.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [October 7, 2008, 8:44pm UTC](https://www.ruby-forum.com/t/rinq/150280/8 "2008-10-07T20:44:14Z")

</div>

On Oct 7, 12:17 pm, Trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [October 7, 2008, 9:21pm UTC](https://www.ruby-forum.com/t/rinq/150280/9 "2008-10-07T21:21:50Z")

</div>

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

-Brian
