Comments (4)
hi @fredwillmore , it looks like the behaviour you are describing is covered by unit tests https://github.com/jamis/bulk_insert/blob/master/test/bulk_insert_test.rb . Can you confirm you can reproduce it consistently?
from bulk_insert.
I was surprised by this as well.
The test sets an outer result
variable from inside the block. So this is the way to access the worker and result_sets when using values or a block with the existing code.
bulk_insert/test/bulk_insert_test.rb
Lines 9 to 13 in ab5db08
However, the README indicates that a worker would be returned when using a block.
Lines 176 to 192 in ab5db08
As mentioned in the original issue comment, the worker is only returned if no values are present and no block is given.
bulk_insert/lib/bulk_insert.rb
Lines 11 to 25 in ab5db08
I think it should be appropriate to always return the worker. Maybe something like this?
def bulk_insert #…
# …
if values.present?
transaction do
worker.add_all(values)
worker.save!
end
elsif block_given?
transaction do
yield worker
worker.save!
end
else
worker
end
from bulk_insert.
@jamis do you remember why you choose to return nil
when implementing this feature here? 95a0c43
from bulk_insert.
I don't remember exactly. :/ However, looking at the diff, I suspect it was an attempt to make the return value consistent, so that it always returns either a worker object, or nil
. I vaguely remember being worried about the consequences of someone trusting the method to return self
, and introducing a bug when they got a worker object back instead.
from bulk_insert.
Related Issues (20)
- Support for psql ON CONFLICT HOT 4
- Support PostgreSQL 9.5 ON CONFLICT when using ignore: true flag HOT 2
- Bulk Insert Concurrency HOT 3
- Error when default column names are different HOT 2
- Not null contraint but PARAM exists HOT 2
- Support PostgreSQL 9.5 ON CONFLICT DO UPDATE HOT 1
- NoMethodError: undefined method 'result_sets' for nil:NilClass HOT 3
- Why the ID column is being removed from default columns HOT 2
- Result returned from INSERT is nil HOT 9
- Abstract database-specific statements HOT 7
- Falsey column defaults not used HOT 1
- Deprecate the lib since Rails 6.x HOT 2
- Update duplicates option currently updates all columns which may not be desirable
- Drop support for Ruby < 2.4
- CI: fix ruby 2.7 build HOT 1
- Before/After create callbacks HOT 1
- bulk_insert version 1.8.1 doesn't play nice with activerecord and mysql2 HOT 2
- before_create not working, Is there any solution?
- Incorrect default value inserted for JSON column types
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bulk_insert.