<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Brainspl.at: New release of ez_where plugin</title>
    <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Brainspl.at</description>
    <item>
      <title>"New release of ez_where plugin" by Ezra</title>
      <description>@Erik&lt;br/&gt;&lt;br /&gt;
&lt;pre&gt;

c { id! == 5 }.to_sql
&lt;/pre&gt;</description>
      <pubDate>Tue, 27 Mar 2007 01:16:34 +0000</pubDate>
      <guid>urn:uuid:a73594c3-dfcf-48cc-9c54-b7d39c9ee8cd</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-4062</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Erik</title>
      <description>&lt;p&gt;I'm having trouble creating a condition with a single NOT:&lt;/p&gt;


  def test_EZ_Where_not_problem&lt;br/&gt;
    &amp;nbsp;&amp;nbsp;&amp;nbsp;cond_tmp = EZ::Where::Condition.new&lt;br/&gt;
    &amp;nbsp;&amp;nbsp;&amp;nbsp;tmp2 = cond_tmp.not( c {id==5} )&lt;br/&gt;
    &amp;nbsp;&amp;nbsp;&amp;nbsp;assert_equal ["NOT (id = ?)", 5], tmp2.to_sql&lt;br/&gt;
    &amp;nbsp;&amp;nbsp;&amp;nbsp;# This fails, because ["(id = ?)", 5] is returned&lt;br/&gt;
  end&lt;br/&gt;
&lt;br/&gt;
&lt;p&gt;How can you create a single NOT condition?&lt;/p&gt;</description>
      <pubDate>Mon, 26 Mar 2007 12:04:17 +0000</pubDate>
      <guid>urn:uuid:763384a7-7c0d-4fa3-9fc3-c1974230a6dd</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-4059</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Jason</title>
      <description>can you do REGEX or RLIKE conditions?</description>
      <pubDate>Fri, 23 Feb 2007 21:25:23 +0000</pubDate>
      <guid>urn:uuid:70bab0f5-10cb-489a-9d08-59b8f669ff3f</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3999</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Don Guernsey</title>
      <description>Great Plugin! How do you do case insensitive searches?</description>
      <pubDate>Sun, 18 Feb 2007 01:37:25 +0000</pubDate>
      <guid>urn:uuid:608a0e35-37cb-480b-a6bf-36a4a3d16507</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3987</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Mr. Linux</title>
      <description>This ne API is much better. I was using the old one. This plugin is the most useful. Especially the nested include I like a lot. Thanks for realeasing this.</description>
      <pubDate>Sat, 06 Jan 2007 11:34:22 +0000</pubDate>
      <guid>urn:uuid:ab3bb559-b517-414c-bd1b-338f5c3e3b90</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3878</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Gamelexi</title>
      <description>Wow great. The nested includes are working well. Thats what i looked for. Thanks!</description>
      <pubDate>Thu, 21 Sep 2006 15:55:48 +0000</pubDate>
      <guid>urn:uuid:d483752f-d9f0-40f2-9120-847938d7d7fa</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3680</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by namxam</title>
      <description>I haven't tried the plugin, but from what i have seen so far, it is exactly what i am looking for. amazing!
Now I need something for dynamically creating group_by statements ;)</description>
      <pubDate>Mon, 11 Sep 2006 16:48:58 +0000</pubDate>
      <guid>urn:uuid:c6551488-dffe-44b9-afc7-6bfaf058d54a</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3630</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Martin</title>
      <description>I tried to get the new version at:
&lt;br/&gt;
&lt;strong&gt;    svn://rubyforge.org//var/svn/ez-where 
&lt;/strong&gt;&lt;br/&gt;
I got the following error mesage:
&lt;br/&gt;&lt;strong&gt;
svn: Can't connect to host 'rubyforge.org': Permission denied
&lt;/strong&gt;
&lt;br/&gt;
Can anyone help, please?
&lt;br/&gt;
Thanks.</description>
      <pubDate>Mon, 14 Aug 2006 23:22:18 +0000</pubDate>
      <guid>urn:uuid:e98c540f-080d-41ac-a482-35d3502d00c6</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3526</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Jeroen</title>
      <description>Found it myself; Condition has a create_clause method which takes care of what I want.</description>
      <pubDate>Thu, 10 Aug 2006 08:47:15 +0000</pubDate>
      <guid>urn:uuid:d51a7ac7-3c68-45e5-946c-34049b6252ed</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3511</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Jeroen</title>
      <description>Thanks for the plugin, works great. However, I'm trying to get something done, but it's not working, maybe you can help. 

Users of my search form are allowed to specify whether they want a field to be &lt;=, ==, &gt;= to a certain value. Rather than doing: 
case (comparator)
when "=="
  field == value
when "&lt;="
  field &lt;= value
when "&gt;="
  field &gt;= value
end

I'd like to do something like

send((field + comparator).to_sym, value)

But that doesn't work. Any idea?</description>
      <pubDate>Wed, 09 Aug 2006 15:29:13 +0000</pubDate>
      <guid>urn:uuid:5f0c0f0c-1ad4-4531-aa7c-793defa7dfac</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3510</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by ayuer</title>
      <description>Thanks man, really cool!</description>
      <pubDate>Fri, 04 Aug 2006 03:01:29 +0000</pubDate>
      <guid>urn:uuid:6d41f699-94ea-48dd-9b86-b0bc1628336c</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3505</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Wiktor</title>
      <description>Great!

Nested includes are working! That is what I was looking forward to.

Thanks Ezra!</description>
      <pubDate>Mon, 03 Jul 2006 12:58:03 +0000</pubDate>
      <guid>urn:uuid:cf861b28-4ecd-4178-9f24-e73578761ffc</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3280</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Peter Krantz</title>
      <description>Ezra, thank you very much! Your plugin is one of the most useful I have tried. You have saved me a lot of work when building advanced search forms. </description>
      <pubDate>Sun, 02 Jul 2006 20:37:34 +0000</pubDate>
      <guid>urn:uuid:05eb6355-c9e4-447c-8cdb-4451a0eeb9e5</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3226</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Ezra</title>
      <description>Thanks Luis, I'm glad you like it!</description>
      <pubDate>Sun, 02 Jul 2006 03:11:27 +0000</pubDate>
      <guid>urn:uuid:7c94dd4d-0491-4dad-95bc-e51e5f329d9e</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3173</link>
    </item>
    <item>
      <title>"New release of ez_where plugin" by Luis Lavena</title>
      <description>Ezra, your plugin is amazing!

I love the ruby way of sql ;-)

(I hate do sql queries)

Thank you for your work!</description>
      <pubDate>Sat, 01 Jul 2006 04:49:56 +0000</pubDate>
      <guid>urn:uuid:f46ce472-7bde-40f2-a6d8-d3b843760979</guid>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin#comment-3068</link>
    </item>
    <item>
      <title>New release of ez_where plugin</title>
      <description>Fabien Franzen and I have created a new release of the ez-where plugin with many new features and a much nicer API. Some things have changed including module and class names so if you are using an old verion and want to update you will have to make a few small search and replace changes. Change Caboose::EZ::Condition to EZ::Where::Condition. Other then that your old code should work fine.
&lt;br /&gt;&lt;br /&gt;
But the new API is much nicer to use. And we have added support for multi search easier by excluding nil or empty values from a search. &lt;br /&gt;&lt;br /&gt;
So instead of:
&lt;pre&gt;
cond = EZ::Where::Condition.new :my_table do
  title =~ "%#{params[:search]}%" unless params[:search].blank?
  user == params[:user] unless params[:user].blank?
end
&lt;/pre&gt;
You can do:
&lt;pre&gt;
cond = EZ::Where::Condition.new :my_table do
  title =~ "%#{params[:search]}%"
  user == params[:user]
end
&lt;/pre&gt;
And if any of the right hand side values are blank? that whole line will be excluded from the query. &lt;br /&gt;&lt;br /&gt;
There are way too many new features to list here so I will show some of the highlights. The huge test cases are currently the best place to look to see all the things this plugin can do. I will wrtie up a few more tutorials soon on some even more advanced features like compositions. &lt;br /&gt;&lt;br /&gt;
So without further ado, here are some cool things you can do with the new version:
&lt;pre&gt;
# find all posts where with body LIKE '%rails%'
@posts = Post.find_where(:all) { |p| p.body =~ "%rails%" }
=&gt;  ["posts.body LIKE ?", "%rails%"]

# find all posts where with title, body or extended LIKE '%rails%'
@posts = Post.find_where :all do |post|
  post.any_of(:title, :body, :extened) =~ '%rails%'
end  
=&gt; ["(posts.title LIKE ? OR posts.body LIKE ? 
    OR posts.extended LIKE ?)", "%rails%", "%rails%", "%rails%"]

# 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 =&gt; [:author, { :comments =&gt; :users }]) do
  |article, author, comment|
   article.any_of(:title, :body, :extended) =~ "%#{params[:search]}%"
   any {
     author.name == params[:author]
     comment.body =~ "%#{params[:search]}%"
   }
end
=&gt;["(articles.title LIKE ? OR articles.body LIKE ? 
   OR articles.extended LIKE ?) AND ((authors.name = ?)
   OR (comments.body LIKE ?))", "%foo%", "%foo%", "%foo%", "Ezra", "%foo%"]


     One of the coolest new features is the c method. This promotes conditions
into first class objects. It works like this:

c{ title =~ '%foo%' }.to_sql
=&gt; ["title LIKE ?", "%foo%"]
With a naked block like this it just converts whats inside the block 
into a condition.


c(:posts) {  title =~ '%foo%' }.to_sql  
=&gt; ["posts.title LIKE ?",  "%foo%"] 
When you give it a plural table name as  an arguments it scopes the condition to that
table.

You can also use the c object directly in a find like so:

Post.find :all, :conditions =&gt; c{ body =~ '%rails%' }


Now that you can have conditions as objects you can do some really interesting
and complex queries with them. You can use operators to define how 
the conditions get strung together. So:

+ == AND   
| == OR      
- == AND NOT 

For example:

cond1 = c(:posts) { body =~ '%rails%'}
cond2 = c(:comments) { username == 'ezmobius'}
cond3 = c(:posts) { author_id === (1..4) }
(cond1 + cond2 | cond3).to_sql
=&gt; ["((posts.body LIKE ?) AND (comments.username = ?)) 
    OR (posts.author_id IN (?))", "%rails%", "ezmobius", [1, 2, 3, 4]]
    
Now you can pass these into a find like this and .to_sql will 
automatically be called on the compound condition:

Post.find :all, :conditions =&gt; (cond1 + cond2 | cond3)

You can also build up one compound condition use +=, -= or |=
 
cond = c{ title =~ '%ruby%' }
cond += c{ description =~ '%ez-where%' }
cond |= c{ user_id === (1..5) }
cond -= c{ pub_date &gt; Time.now.to_s(:db) }
Post.find :all, :conditions =&gt; cond
=&gt; ["((title LIKE ?) AND (description LIKE ?)) 
    OR ((user_id IN (?)) AND NOT (pub_date &gt; ?))",
    "%ruby%", "%ez-where%", [1, 2, 3, 4, 5], "2006-06-21 01:17:47"]


&lt;/pre&gt;
Get it here:&lt;br /&gt;
$ script/plugin install svn://rubyforge.org//var/svn/ez-where &lt;br /&gt;&lt;br /&gt;
I moved the project to rubyforge so there is now a mailing list where you can ask questions or contribute ideas.
&lt;br /&gt;&lt;br /&gt;


&lt;a href='http://rubyforge.org/mailman/listinfo/ez-where-devel'&gt;http://rubyforge.org/mailman/listinfo/ez-where-devel&lt;/a&gt;


Enjoy! ;)</description>
      <pubDate>Fri, 30 Jun 2006 19:58:00 +0000</pubDate>
      <guid>urn:uuid:0310392c-4e73-46e1-8b5d-4c12f08286c8</guid>
      <author>ezmobius</author>
      <link>http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin</link>
      <category>conditions</category>
      <category>where</category>
      <category>ez</category>
      <trackback:ping>http://www.brainspl.at/articles/trackback/3035</trackback:ping>
    </item>
  </channel>
</rss>

