More Where Clause goodness.

Posted by ezmobius Wed, 04 Jan 2006 23:44:00 GMT


I have been working on the where plugin some more trying to make the syntax a bit more natural ruby. Here is what the latest version looks like to use:

Model.find_with_conditons( :all, :limit => ..., :order => ... ) do 
  foo == 'bar'       # ["foo = ?", 'bar]
  baz <=> (1..100)   # ["baz BETWEEN ?AND ?", 1,100]
  woo =~ 'substri%'  # ["woo LIKE ?", 'substri%']
  id === (1..4)      # ["id IN (?)", [1,2,3,4]]
  fiz < 10           # lt, gt, leq, geq, etc., should all "just work" 
end

I like this because now it really just looks like ruby. Gotta love using the spaceship operator <=> to sugnify a [BETWEEN ? and ?, 1, 10]! The =~ or regex match operatpr in ruby gets converted into a LIKE query in the db. Also just added IN (?) support using the === operator. And you can still use :limit, :order and :joins plus :all or :first and it just works. I still need to convert the tests to use the new syntax so that will be done this weekend.

You can get the development version here if you want to play now. Or wait until the weekend when I add a few more features like the ability to use OR instead of AND for arbitrary items in the :conditions clause.

http://OpenSVN.csie.org/ezra/rails/plugins/ez_where

Posted in ,  | 6 comments

Comments

  1. Duane Johnson said 19 days later:
    Hi Ezra--curious to know if you've gone any further with the arbitrarily nested AND and OR clauses. btw... I finally saw the double-meaning for 'ez_where'... nice ;)
  2. free lg ringtone verizon wireless said 163 days later:
    You have so amazing blog!!!
  3. masukomi said 339 days later:
    Ok, this is freaking awesome. It's been bugging me for ages that ActiveRecord is supposed to abstract away the SQL and yet we end up just writing SQL where clauses in our conditions block. It's not much better than just writing out the pure sql.
  4. Pharmacy said 391 days later:
    the AND OR classes not supported here
  5. suncasino said 398 days later:
    SUN CASINO SUN CASINO - #1 Online Casino! Join now and get up to $150. Poker, Blackjack, Slots, Roulette, Craps. Earn more than $800,000 with jackpots. Play for real money or just for fun. [url]http://www.suncasino.eu[/url] VIP CASINO VIP CASINO - online flash casino games. No need to install - play over all the world. Join today and earn $750 free. Play Poker, Blackjack, Slots, Roulette, Craps for real money or just for fun. [url]http://www.vipcasino.lv[/url]
  6. suncasino said 398 days later:
    SUN CASINO SUN CASINO - #1 Online Casino! Join now and get up to $150. Poker, Blackjack, Slots, Roulette, Craps. Earn more than $800,000 with jackpots. Play for real money or just for fun. [url]http://www.suncasino.eu[/url] VIP CASINO VIP CASINO - online flash casino games. No need to install - play over all the world. Join today and earn $750 free. Play Poker, Blackjack, Slots, Roulette, Craps for real money or just for fun. [url]http://www.vipcasino.lv[/url]

(leave url/email »)

   Preview comment