Skip to content

Commit 4fb4c8c

Browse files
Make batch_update_statements_public (#9)
1 parent 80fe3d6 commit 4fb4c8c

File tree

6 files changed

+15
-18
lines changed

6 files changed

+15
-18
lines changed

.github/workflows/tests.yml

+3-13
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,14 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515

16-
- name: Set up Ruby
16+
- name: Set up Ruby and Bundler
1717
uses: ruby/setup-ruby@v1.196.0
1818
with:
1919
ruby-version: 3.3.4
2020
bundler-cache: true
2121

22-
- name: Install dependencies
23-
run: bundle install
24-
25-
- name: Install pre-commit
26-
run: |
27-
sudo apt-get update
28-
sudo apt-get install --yes --no-install-recommends python3 python3-pip
29-
pip install pre-commit
30-
pre-commit install --install-hooks
31-
32-
- name: Run linters
33-
run: pre-commit run --all-files
22+
- name: Setup pre-commit and run linters
23+
uses: pre-commit/action@v3.0.1
3424

3525
- name: Run tests
3626
run: bin/rspec

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
batch_update (0.0.1)
4+
batch_update (0.0.2)
55
activerecord (~> 7.0)
66
activesupport (~> 7.0)
77

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,12 @@ Specify a different batch size (100 by default):
5353
Cat.batch_update(cats, columns: :all, batch_size: 1000)
5454
```
5555

56+
Generate the relevant SQL statements:
57+
```ruby
58+
Cat.batch_update_statements([{id: 1, name: 'Lilly'}, {id: 2, name: 'John'}]).each do |query|
59+
Cat.connection.execute(query)
60+
end
61+
```
62+
5663
## License
5764
MIT

batch_update.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |s|
44
s.name = 'batch_update'
5-
s.version = '0.0.1'
5+
s.version = '0.0.2'
66
s.summary = 'Update multiple records with different values in a small number of queries'
77
s.description = 'A simple hello world gem'
88
s.authors = ['Quentin de Metz']

lib/batch_update.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ def batch_update(entries, columns:, batch_size: 100, validate: true)
3939
updated_count
4040
end
4141

42-
private
43-
4442
def batch_update_statements(entries, update_on: :id, batch_size: 100)
4543
update_on = Array.wrap(update_on).map(&:to_s)
4644

@@ -62,6 +60,8 @@ def batch_update_statements(entries, update_on: :id, batch_size: 100)
6260
end
6361
end
6462

63+
private
64+
6565
def cte_table
6666
@cte_table ||= Arel::Table.new('batch_updates')
6767
end

spec/batch_update_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
describe BatchUpdate do
66
describe '#batch_update_statements' do
7-
subject(:sql_queries) { Cat.__send__(:batch_update_statements, cats, **kwargs) }
7+
subject(:sql_queries) { Cat.batch_update_statements(cats, **kwargs) }
88

99
let(:cats) { [] }
1010
let(:kwargs) { {} }

0 commit comments

Comments
 (0)