SqlLogic, generate complex sql sentence for ActiveRecord finder

Inspired from SearchLogic, but lighter and focused in sql sentence generation.

Install

$ sudo gem install sql_logic

Usage

require 'rubygems'
gem "activerecord"
require 'sql_logic'
#table migration
#create_table :users do |t|
#  t.string :username
#  t.string :email
#  t.string :phone
#  t.string :sex
#  t.timestamps
#end
class User < ActiveRecord::Base; end
p User.user_name_like_to_sql("Wayne") # => ["lower(users.user_name) LIKE :users_user_name", {:users_user_name=>"%wayne%"}]
sql_hash = User.get_sql_by_hash({:user_name_like=>"Wayne", :id_lt=>100})
User.all(:conditions=>sql_hash)
#For View
#<%= text_field_tag "user_name_like", params[:user_name_like], :size=>8 -%>
#<%= select_tag "sex_eq", options_for_select([["", "M", "F"]}, params[:sex_eq]) -%>
#For Controller
User.all(:conditions=> User.get_sql_by_hash(params))

Copyright © 2011 MIT-LICENSE Author : Wayne Deng Web : blog.waynedeng.com Email : wayne.deng.cn(AT).com