提交 df9c972a 编写于 作者: R Ryuta Kamizono

Place `PartialQuery` and `PartialQueryCollector` in the same file

上级 859fba7c
......@@ -35,7 +35,7 @@ def cacheable_query(klass, arel) # :nodoc:
sql, binds = visitor.compile(arel.ast, collector)
query = klass.query(sql)
else
collector = PartialQueryCollector.new
collector = klass.partial_query_collector
parts, binds = visitor.compile(arel.ast, collector)
query = klass.partial_query(parts)
end
......@@ -507,28 +507,6 @@ def with_yaml_fallback(value)
value
end
end
class PartialQueryCollector
def initialize
@parts = []
@binds = []
end
def <<(str)
@parts << str
self
end
def add_bind(obj)
@binds << obj
@parts << Arel::Nodes::BindParam.new(1)
self
end
def value
[@parts, @binds]
end
end
end
end
end
......@@ -44,7 +44,7 @@ class PartialQuery < Query # :nodoc:
def initialize(values)
@values = values
@indexes = values.each_with_index.find_all { |thing, i|
Arel::Nodes::BindParam === thing
Substitute === thing
}.map(&:last)
end
......@@ -56,6 +56,28 @@ def sql_for(binds, connection)
end
end
class PartialQueryCollector
def initialize
@parts = []
@binds = []
end
def <<(str)
@parts << str
self
end
def add_bind(obj)
@binds << obj
@parts << Substitute.new
self
end
def value
[@parts, @binds]
end
end
def self.query(sql)
Query.new(sql)
end
......@@ -64,6 +86,10 @@ def self.partial_query(values)
PartialQuery.new(values)
end
def self.partial_query_collector
PartialQueryCollector.new
end
class Params # :nodoc:
def bind; Substitute.new; end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册