public
Description: An SQL condition builder tool
Homepage: http://code.google.com/p/railswhere/
Clone URL: git://github.com/timcharper/railswhere.git
name age message
file CHANGELOG Tue Apr 29 23:37:26 -0700 2008 added changelog [timcharper]
file MIT-LISCENSE Tue May 15 13:18:06 -0700 2007 Initial import git-svn-id: http://railswhere.g... [timcharper]
file README Tue May 15 14:46:13 -0700 2007 rdoc documentation git-svn-id: http://railswhe... [timcharper]
file init.rb Tue Nov 13 09:36:55 -0800 2007 search builder git-svn-id: http://railswhere.g... [timcharper]
directory lib/ Tue Sep 08 05:02:07 -0700 2009 :sanitize_sql_array is the new :sanitize_sql [timcharper]
directory spec/ Tue Sep 08 05:01:46 -0700 2009 default sql is (true) [timcharper]
README
= Where clause generator
== Author: Tim Harper ( "timseeharperATgmail.seeom".gsub("see", "c").gsub("AT", "@") )

<b>Usage example</b>

=== Returning SQL

 sql = Where.new('x=?',5).and( Where.new('x=?',6).or('x=?',7)).to_s
 # returns (x=5) and ( ( x=6 ) or ( x=7 ) ) 
 
=== Building a complicated where clause made easy
 
 def get_search_query_string
 
   where = Where.new
   where.and('users.first_name like ?', params[:search_first_name] + '%') unless params[:search_first_name].blank?
   where.and('users.last_name like ?', params[:search_last_name] + '%') unless params[:search_last_name].blank?
 
   status_where = Where.new
   for status in params[search_statuses].split(',')
     status_where.or 'status=?', status
   end
   where.and status_where unless status_where.blank?
 
   where.to_s
 end
 
User.find(:all, :conditions => get_search_query_string)
 
===  Inline
 
   User.find(:all, :conditions => Where.new('first_name like ?', 'Tim').and('last_name like ?', 'Harper') )
   # Sweet chaining action!