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 http://www.thoughtbot.com -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Matthew Margolis
2006-Sep-29 21:41 UTC
Re: [ANN] Squirrel plugin for better looking queries
Jon Yurek wrote:> 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 > 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 Margolis blog.mattmargolis.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Daniel Higginbotham
2006-Sep-30 01:19 UTC
Re: [ANN] Squirrel plugin for better looking queries
This looks very nice. You might want to check out ez_where though On Friday 29 September 2006 8:49 am, Jon Yurek wrote:> 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 > http://www.thoughtbot.com--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Michael Campbell
2006-Sep-30 01:59 UTC
Re: [ANN] Squirrel plugin for better looking queries
Looks like he has... On 9/29/06, Daniel Higginbotham <daniel-4cOk6EWy6wjNj93mkU9IYrqjc7CnNF17@public.gmane.org> wrote:> > This looks very nice. You might want to check out ez_where though > > On Friday 29 September 2006 8:49 am, Jon Yurek wrote:> > (before you ask, yes, I cribbed the syntax from ez_where, > > since it makes sense).--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
This is great, thank you. Going to check it out. On 9/29/06, Michael Campbell <michael.campbell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Looks like he has... > > On 9/29/06, Daniel Higginbotham <daniel-4cOk6EWy6wjNj93mkU9IYrqjc7CnNF17@public.gmane.org> wrote: > > > > This looks very nice. You might want to check out ez_where though > > > > On Friday 29 September 2006 8:49 am, Jon Yurek wrote: > > > > (before you ask, yes, I cribbed the syntax from ez_where, > > > since it makes sense). > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---