diff options
Diffstat (limited to 'lib/active_relation/sql.rb')
-rw-r--r-- | lib/active_relation/sql.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/active_relation/sql.rb b/lib/active_relation/sql.rb new file mode 100644 index 0000000000..89f6193cd8 --- /dev/null +++ b/lib/active_relation/sql.rb @@ -0,0 +1,51 @@ +module ActiveRelation + module Sql + module Quoting + def connection + ActiveRecord::Base.connection + end + + delegate :quote_table_name, :quote_column_name, :quote, :to => :connection + end + + class Strategy + include Quoting + end + + class Projection < Strategy + def attribute(relation_name, attribute_name, aliaz) + "#{quote_table_name(relation_name)}.#{quote_column_name(attribute_name)}" + (aliaz ? " AS #{quote(aliaz.to_s)}" : "") + end + + def select(select_sql) + "(#{select_sql})" + end + end + + class Predicate < Strategy + def attribute(relation_name, attribute_name, aliaz) + "#{quote_table_name(relation_name)}.#{quote_column_name(attribute_name)}" + end + + def scalar(scalar) + scalar + end + + def select(select_sql) + "(#{select_sql})" + end + end + + class Select < Strategy + def select(select_sql) + select_sql + end + end + + class Scalar < Strategy + def scalar(scalar) + quote(scalar) + end + end + end +end
\ No newline at end of file |