|
EnglishLikeQueries
English like queries instructions and install directions
IntroductionThis is a rails plugins allowing you to have nice, easy to read, easy to type statements than the traditional ActiveRecord syntax of instances = School.find :all, :conditions => ["name LIKE '?%'", George'] Ex: School.where 'name starts with' => 'George' # like an english sentence People.where 'id in' => [35,36,37] # either id is 35, 36, or 37 People.where 'id in' => [35..37, 490, 499..588] # handles compound arrays and such nicely. People.where 'name doesnt include' => ['fred'] person = People.first_where 'email address' => 'fred@fred.com' person = People.fwhere 'email address' => 'fred@fred.com' # fwhere == first_where -- less typing person.orders.where 'price >' => 6.00 # fred's orders over $6. People.where 'name matches' => /t+tt$/ # handles ruby regexp's, as well as just text [which will be interpreted as a regex] People.where 'date created > ' => Time.now # it adds in missing _'s if they are needed Also allows for things like case insensitivity, by adding the word sensitive an s People.where 'name includes' => ['george', 'park'] # defaults to insensitive People.where 'name sensitive includes' => ['george', 'park'] # case sensitive People.where 'name sincludes' => ['george', 'park'] # or abbreviate 'sensitive' as s It is very addictive! Detailsinstall thus: script/plugin install http://ruby-roger-useful-functions.googlecode.com/svn/trunk/rails/english_like_queries from your rails app root directory then run script/console and test it out! on windows: ruby script\plugin install http://ruby-roger-useful-functions.googlecode.com/svn/trunk/rails/english_like_queries Note that this is still alpha and probably will never be released, per se, but it still works like a charm, and be very very friendly. You may never want to use :conditions => ... again. Its cousins, with lesser english like ability, are listed here. Any feedback is welcome! Leave a comment at all! |
Sign in to add a comment
works with rails 2 and mysql probably with others? you can also do
you can also use 'gte' stuff, like Lead.where 'date_created gte' => Time.now
you can also use activerecord instance
version as of june 6 12:40 pm now includes
similar to AR's find.
works with booleans, too
instance.programs.all_where('enabled' => true) # if that field is a boolean, rails converts it over nicelyIs School.fwhere some other function or just typo of where? Typos in code are very confusing :-)
fixed it -- it's just a shortcut for first_where and confusing yes :)
Here's an example of 'case sensitive equals'
Here's an example case sensitive regexs is the default?: