[ANN] Squirrel plugin for better looking queries

This is the first release of a new plugin for making very Rubyish
queries. I never really liked AR’s find method syntax, and all the
replacements I’ve seen didn’t make it any easier to join on multiple
models at the same time, so I wrote Squirrel.

posts = Post.find do
user.email =~ “%thoughtbot%”
tags.name === %w( ruby rails )
created_on <=> [ Time.now - 2.weeks, Time.now - 1.week ]
end

It overloads the base find method to take a block to build conditions,
including any and all association joins. You reference them like you
would in a normal block of Ruby.

You reference associations by whatever name you gave to it in the
has_many, belongs_to, etc. You can then access all the columns and
relationships on that model. It is rather specific, though, and will
raise errors if you misspell your relationships or donâ??t pluralize
right.

And you simply reference columns by their normal names and use any of
==, ===, <=>, =~, >=, <=, >, and < on them pretty much like youâ??d expect
to be able to (before you ask, yes, I cribbed the syntax from ez_where,
since it makes sense). It handles nil values in == with a quick trip to
IS NULL and it handles negation of conditions through the unary -.

It’s not as full featured as I’d like it – yet, but IMHO it looks a lot
better, and it’s still useful.

You can read further about it at
http://giantrobots.thoughtbot.com/2006/9/29/an-improvement-for-querying-in-rails

Or you can install it via script/plugin install
http://svn.thoughtbot.com/plugins/squirrel

Jon Yurek

Jon Yurek wrote:

And you simply reference columns by their normal names and use any of

Or you can install it via script/plugin install
http://svn.thoughtbot.com/plugins/squirrel

Jon Yurek
http://www.thoughtbot.com

This looks really cool. I have a use for this in a project. I will let
you know how it works out.

Matthew M.
blog.mattmargolis.net

This looks very nice. You might want to check out ez_where though

Looks like he has…

On 9/29/06, Daniel H. [email protected] wrote:

This looks very nice. You might want to check out ez_where though

This is great, thank you. Going to check it out.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs