./README in ambition-0.1.4 vs ./README in ambition-0.1.5

- old
+ new

@@ -47,15 +47,15 @@ though. Mostly ignore these methods and treat everything like you normally would. See, +to_sql+: >> User.select { |m| m.name == 'jon' }.to_sql - => "SELECT * FROM users WHERE users.`name` = 'jon'" + => "SELECT * FROM users WHERE users.name = 'jon'" See, +to_hash+: >> User.select { |m| m.name == 'jon' }.to_hash - => {:conditions=>"users.`name` = 'jon'"} + => {:conditions=>"users.name = 'jon'"} == Limitations You can use variables, but any more complex Ruby (right now) won't work inside your blocks. Just do it outside the block and assign it to a variable. @@ -70,110 +70,110 @@ Instance variables and globals work, too. Same with method calls. == Equality -- select { |u| u.field == 'bob' } User.select { |m| m.name == 'jon' } - "SELECT * FROM users WHERE users.`name` = 'jon'" + "SELECT * FROM users WHERE users.name = 'jon'" User.select { |m| m.name != 'jon' } - "SELECT * FROM users WHERE users.`name` <> 'jon'" + "SELECT * FROM users WHERE users.name <> 'jon'" User.select { |m| m.name == 'jon' && m.age == 21 } - "SELECT * FROM users WHERE (users.`name` = 'jon' AND users.`age` = 21)" + "SELECT * FROM users WHERE (users.name = 'jon' AND users.age = 21)" User.select { |m| m.name == 'jon' || m.age == 21 } - "SELECT * FROM users WHERE (users.`name` = 'jon' OR users.`age` = 21)" + "SELECT * FROM users WHERE (users.name = 'jon' OR users.age = 21)" User.select { |m| m.name == 'jon' || m.age == 21 && m.password == 'pass' } - "SELECT * FROM users WHERE (users.`name` = 'jon' OR (users.`age` = 21 AND users.`password` = 'pass'))" + "SELECT * FROM users WHERE (users.name = 'jon' OR (users.age = 21 AND users.password = 'pass'))" User.select { |m| (m.name == 'jon' || m.name == 'rick') && m.age == 21 } - "SELECT * FROM users WHERE ((users.`name` = 'jon' OR users.`name` = 'rick') AND users.`age` = 21)" + "SELECT * FROM users WHERE ((users.name = 'jon' OR users.name = 'rick') AND users.age = 21)" == Associations -- select { |u| u.field == 'bob' && u.association.field == 'bob@bob.com' } The +to_sql+ method doesn't work on associations yet, but that's okay: they can still query through ActiveRecord just fine. User.select { |u| u.email == 'chris@ozmm.org' && u.profile.name == 'chris wanstrath' }.map(&:title) - SELECT users.`id` AS t0_r0, ... FROM users LEFT OUTER JOIN profiles ON profiles.user_id = users.id WHERE ((users.`email` = 'chris@ozmm.org' AND profiles.name = 'chris wanstrath')) + SELECT users.id AS t0_r0, ... FROM users LEFT OUTER JOIN profiles ON profiles.user_id = users.id WHERE ((users.email = 'chris@ozmm.org' AND profiles.name = 'chris wanstrath')) == Comparisons -- select { |u| u.age > 21 } User.select { |m| m.age > 21 } - "SELECT * FROM users WHERE users.`age` > 21" + "SELECT * FROM users WHERE users.age > 21" User.select { |m| m.age < 21 }.to_sql - "SELECT * FROM users WHERE users.`age` < 21" + "SELECT * FROM users WHERE users.age < 21" User.select { |m| [1, 2, 3, 4].include? m.id } - "SELECT * FROM users WHERE users.`id` IN (1, 2, 3, 4)" + "SELECT * FROM users WHERE users.id IN (1, 2, 3, 4)" == LIKE and REGEXP (RLIKE) -- select { |m| m.name =~ 'chris' } User.select { |m| m.name =~ 'chris' } - "SELECT * FROM users WHERE users.`name` LIKE 'chris'" + "SELECT * FROM users WHERE users.name LIKE 'chris'" User.select { |m| m.name =~ 'chri%' } - "SELECT * FROM users WHERE users.`name` LIKE 'chri%'" + "SELECT * FROM users WHERE users.name LIKE 'chri%'" User.select { |m| m.name !~ 'chris' } - "SELECT * FROM users WHERE users.`name` NOT LIKE 'chris'" + "SELECT * FROM users WHERE users.name NOT LIKE 'chris'" User.select { |m| !(m.name =~ 'chris') } - "SELECT * FROM users WHERE users.`name` NOT LIKE 'chris'" + "SELECT * FROM users WHERE users.name NOT LIKE 'chris'" User.select { |m| m.name =~ /chris/ } - "SELECT * FROM users WHERE users.`name` REGEXP 'chris'" + "SELECT * FROM users WHERE users.name REGEXP 'chris'" == #detect User.detect { |m| m.name == 'chris' } - "SELECT * FROM users WHERE users.`name` = 'chris' LIMIT 1" + "SELECT * FROM users WHERE users.name = 'chris' LIMIT 1" == LIMITs -- first, first(x), [offset, limit], [range], slice User.select { |m| m.name == 'jon' }.first - "SELECT * FROM users WHERE users.`name` = 'jon' LIMIT 1" + "SELECT * FROM users WHERE users.name = 'jon' LIMIT 1" User.select { |m| m.name == 'jon' }.first(5) - "SELECT * FROM users WHERE users.`name` = 'jon' LIMIT 5" + "SELECT * FROM users WHERE users.name = 'jon' LIMIT 5" User.select { |m| m.name == 'jon' }[10, 20] - "SELECT * FROM users WHERE users.`name` = 'jon' LIMIT 10, 20" + "SELECT * FROM users WHERE users.name = 'jon' LIMIT 10, 20" User.select { |m| m.name == 'jon' }[10..20] - "SELECT * FROM users WHERE users.`name` = 'jon' LIMIT 10, 10" + "SELECT * FROM users WHERE users.name = 'jon' LIMIT 10, 10" == ORDER -- sort_by { |u| u.field } User.select { |m| m.name == 'jon' }.sort_by { |m| m.name } - "SELECT * FROM users WHERE users.`name` = 'jon' ORDER BY users.name" + "SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.name" User.select { |m| m.name == 'jon' }.sort_by { |m| [ m.name, m.age ] } - "SELECT * FROM users WHERE users.`name` = 'jon' ORDER BY users.name, users.age" + "SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.name, users.age" User.select { |m| m.name == 'jon' }.sort_by { |m| [ m.name, -m.age ] } - "SELECT * FROM users WHERE users.`name` = 'jon' ORDER BY users.name, users.age DESC" + "SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.name, users.age DESC" User.select { |m| m.name == 'jon' }.sort_by { |m| [ -m.name, -m.age ] } - "SELECT * FROM users WHERE users.`name` = 'jon' ORDER BY users.name DESC, users.age DESC" + "SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.name DESC, users.age DESC" User.select { |m| m.name == 'jon' }.sort_by { |m| -m.age } - "SELECT * FROM users WHERE users.`name` = 'jon' ORDER BY users.age DESC" + "SELECT * FROM users WHERE users.name = 'jon' ORDER BY users.age DESC" User.select { |m| m.name == 'jon' }.sort_by { |m| -m.profiles.title } - "SELECT users.`id` AS t0_r0, ... FROM users LEFT OUTER JOIN profiles ON profiles.user_id = users.id - WHERE (users.`name` = 'jon') ORDER BY profiles.title DESC" + "SELECT users.id AS t0_r0, ... FROM users LEFT OUTER JOIN profiles ON profiles.user_id = users.id + WHERE (users.name = 'jon') ORDER BY profiles.title DESC" User.select { |m| m.name == 'jon' }.sort_by { rand } - "SELECT * FROM users WHERE users.`name` = 'jon' ORDER BY RAND()" + "SELECT * FROM users WHERE users.name = 'jon' ORDER BY RAND()" == COUNT -- select { |u| u.name == 'jon' }.size User.select { |m| m.name == 'jon' }.size - SELECT count(*) AS count_all FROM users WHERE (users.`name` = 'jon') + SELECT count(*) AS count_all FROM users WHERE (users.name = 'jon') >> User.select { |m| m.name == 'jon' }.size => 21 == Other Enumerables @@ -188,11 +188,15 @@ == More Sugar The +downcase+ and +upcase+ methods will map to LOWER() and UPPER(), respectively. >> User.select { |m| m.name.downcase =~ 'jon%' }.to_sql - => "SELECT * FROM users WHERE LOWER(users.`name`) LIKE 'jon%'" - + => "SELECT * FROM users WHERE LOWER(users.name) LIKE 'jon%'" + +== Quoting + +Columns and values will be quoted using ActiveRecord's quote_column_name and quote methods, if +possible. == SELECT * FROM bugs Found a bug? Sweet. Add it at the Lighthouse: http://err.lighthouseapp.com/projects/466-plugins/tickets/new