Hello friends- There is a new release of the ez-where plugin. This plugin makes it easy to do complex ActiveRecord queries without writing any SQL. Ruby operators are mapped to SQL operators like so: foo == ''bar'' #=> ["foo = ?", ''bar''] foo =~ ''%bar'' #=> ["foo LIKE ?", ''%bar''] foo <=> (1..5) #=> ["foo BETWEEN ? AND ?", 1, 5] id === [1, 2, 3, 5, 8] #=> ["id IN(?)", [1, 2, 3, 5, 8]] <, >, >=, <= et all will just work like you expect. So you can use blocks and ruby ops for very complex conditions. Here is a teaser: # find all articles with title, body or extended LIKE "%#{params [:search]}%" # AND (author.name = params[:author] OR comment.body LIKE "%#{params [:search]}%") @articles = Article.find_where(:all, :include => [:author, { :comments => :users }]) do |article, author, comment| article.any_of(:title, :body, :extended) =~ "%#{params[:search]}%" any { author.name == params[:author] comment.body =~ "%#{params[:search]}%" } end =>["(articles.title LIKE ? OR articles.body LIKE ? OR articles.extended LIKE ?) AND ((authors.name = ?) OR (comments.body LIKE ?))", "%foo%", "%foo%", "%foo%", "Ezra", "% foo%"] More examples on my blog: http://brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin Get it here: $ script/plugin install svn://rubyforge.org//var/svn/ez-where Mailing list here: http://rubyforge.org/mailman/listinfo/ez-where-devel Cheers- -Ezra -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060630/50cd5ea9/attachment.html
On Fri, 2006-06-30 at 13:44 -0700, Ezra Zygmuntowicz wrote:> Hello friends- > > > There is a new release of the ez-where plugin. This plugin makes it > easy to do complex ActiveRecord queries without writing any SQL. Ruby > operators are mapped to SQL operators like so: > > > foo == ''bar'' #=> ["foo = ?", ''bar''] > foo =~ ''%bar'' #=> ["foo LIKE ?", ''%bar''] > foo <=> (1..5) #=> ["foo BETWEEN ? AND ?", 1, 5] > id === [1, 2, 3, 5, 8] #=> ["id IN(?)", [1, 2, 3, 5, 8]] > <, >, >=, <= et all will just work like you expect. > > > So you can use blocks and ruby ops for very complex conditions. Here > is a teaser: > > > # find all articles with title, body or extended LIKE "% > #{params[:search]}%" > # AND (author.name = params[:author] OR comment.body LIKE "% > #{params[:search]}%") > > > @articles = Article.find_where(:all, :include => [:author, { :comments > => :users }]) do > |article, author, comment| > article.any_of(:title, :body, :extended) =~ "%#{params[:search]}%" > any { > author.name == params[:author] > comment.body =~ "%#{params[:search]}%" > } > end > =>["(articles.title LIKE ? OR articles.body LIKE ? > OR articles.extended LIKE ?) AND ((authors.name = ?) > OR (comments.body LIKE ?))", "%foo%", "%foo%", "%foo%", "Ezra", "% > foo%"] > > > More examples on my blog: > > > http://brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin > > > Get it here: > $ script/plugin install svn://rubyforge.org//var/svn/ez-where---- ''get it here'' should be on your blog too and by the way - thanks Ezra and Fabien for such a terrific tool Craig
On Jun 30, 2006, at 4:41 PM, Craig White wrote:> On Fri, 2006-06-30 at 13:44 -0700, Ezra Zygmuntowicz wrote: >> Hello friends- >> >> >> There is a new release of the ez-where plugin. This plugin makes it >> easy to do complex ActiveRecord queries without writing any SQL. Ruby >> operators are mapped to SQL operators like so: >> >> >> More examples on my blog: >> >> >> http://brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin >> >> >> Get it here: >> $ script/plugin install svn://rubyforge.org//var/svn/ez-where > ---- > ''get it here'' should be on your blog too > > and by the way - thanks Ezra and Fabien for such a terrific tool > > CraigThanks Craig. I added the link to my blog. Cheers- -Ezra