很高兴你喜欢Kiba!
我会说你的理解是不正确的,这会让你高兴。
行已产生&在Kiba一个接一个地处理。
要了解事情的确切运作方式,我建议你试试这段代码:
class MySource def initialize(enumerable) @enumerable = enumerable end def each @enumerable.each do |item| puts "Source is reading #{item}" yield item end end end class MyDestination def write(row) puts "Destination is writing #{row}" end end source MySource, (1..10) destination MyDestination
运行此命令,您将看到每个项目都被读取然后写入。
现在,根据您的实际具体情况 - 上述内容意味着您可以通过这种方式实现源代码:
class ActiveRecord def initialize(model:) @model = model end def each @model.find_each do |record| yield record end end end
然后你可以像这样使用它:
source ActiveRecordSource, model: Person.where("age > 21")
(你也可以利用 find_in_batches 如果你希望每一行都是多个记录的数组,但这可能不是你需要的那样)。
find_in_batches
希望这能正确回答你的问题!