Agile Web Development

Build it. Launch it. Love it.

ez_where

ez_where maps ruby operators to sql ops. Like this:

articles = Article. find_where(:all, :include => :author) do |article, author| article.title =~ "%Foo Title%" author.any do name == 'Ezra' name == 'Fab' end end

:conditions => ["article.title LIKE ? AND (authors.name = ? OR authors.name = ?)", "%Foo Title%", "Ezra", "Fab"]

Basically here is the breakdown of how we map ruby operators to SQL operators:

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.

There are many more features to this plugin. See the extensive test cases in the plugin for all available options.

Vitals

Home http://brainspl.at/articles/2006/01/30/i-have-been-busy
Repository svn://rubyforge.org//var/svn/ez-where
License Rails' (MIT)
Rating (28 votes)
Owner Ezra Zygmuntowicz & Fabien Franzen
Created 22 April 2006

Comments

Add a comment