diff --git a/Gemfile.lock b/Gemfile.lock index 91e1168..5d71938 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - sequel-batches (2.0.0) + sequel-batches (2.0.1) sequel GEM @@ -25,7 +25,7 @@ GEM method_source (1.0.0) minitest (5.16.2) parallel (1.22.1) - parser (3.1.2.0) + parser (3.1.2.1) ast (~> 2.4.1) pg (1.4.2) pry (0.14.1) @@ -58,7 +58,7 @@ GEM rubocop-ast (>= 1.18.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.19.1) + rubocop-ast (1.21.0) parser (>= 3.1.1.0) rubocop-config-umbrellio (1.30.0.65) rubocop (~> 1.30.0) diff --git a/lib/sequel/extensions/batches/yielder.rb b/lib/sequel/extensions/batches/yielder.rb index f5be65a..9a37cea 100644 --- a/lib/sequel/extensions/batches/yielder.rb +++ b/lib/sequel/extensions/batches/yielder.rb @@ -31,7 +31,7 @@ def call base_ds end - working_ds_pk = working_ds.select(*qualified_pk).order(order_by).limit(of) + working_ds_pk = working_ds.select(*qualified_pk).order(order_by(qualified: true)).limit(of) current_instance = db.from(working_ds_pk).select(*pk).order(order_by).last or break working_ds = working_ds.where(generate_conditions(current_instance.to_h, sign: sign_to_inclusive)) diff --git a/sequel-batches.gemspec b/sequel-batches.gemspec index bff9ccc..0e85ca6 100644 --- a/sequel-batches.gemspec +++ b/sequel-batches.gemspec @@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) Gem::Specification.new do |spec| spec.name = "sequel-batches" - spec.version = "2.0.0" + spec.version = "2.0.1" spec.authors = %w[fiscal-cliff umbrellio] spec.email = ["oss@umbrellio.biz"] spec.required_ruby_version = ">= 2.7" diff --git a/spec/sequel/extensions/batches_spec.rb b/spec/sequel/extensions/batches_spec.rb index 964be67..08889fd 100644 --- a/spec/sequel/extensions/batches_spec.rb +++ b/spec/sequel/extensions/batches_spec.rb @@ -100,6 +100,12 @@ expect { DB[:data, :data2].in_batches }.not_to raise_error end + it "qualifies pk to mitigate ambiguous column error in case of composite pk" do + scope = DB[:data].join(:data2, Sequel[:data][:id] =~ Sequel[:data2][:id]).order(Sequel[:data][:id]) + scope.in_batches(pk: [:created_at, :id], of: 2) { |b| chunks << b.select_map(Sequel[:data][:id]) } + expect(chunks).to eq([[1, 2], [3, 4], [5, 6]]) + end + it "respects order option" do DB[:data].in_batches(of: 3, order: :desc) { |b| chunks << b.select_map(:id) } expect(chunks).to eq([[6, 5, 4], [3, 2, 1]])