umbrellio-utils 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/umbrellio_utils/database.rb +12 -5
- data/lib/umbrellio_utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaa7935344d41de32a9d61527b1c7b167d64715207422fc23f83d790950e5951
|
4
|
+
data.tar.gz: f9d7707ff893d916462b7e584a08ad8171036825eecacc201eecc09b17fc041f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 319224d118b8c1197b9d93855aa83dcb8dbe80b33fb9395d8782e24cbdd4e303ce7bea798f33b4940febfa268d4f457dae0aac55d14e43e5933fd60d9d038362
|
7
|
+
data.tar.gz: fb536f209a2190fc064db5b0f3a73b01b9286deceab3b7ee83e7f88cbb0023203737b29444baf218b42402dd5e0ad2f2a0bc60edf92bbf0cfbceb1352c5c0f84
|
data/Gemfile.lock
CHANGED
@@ -5,6 +5,7 @@ module UmbrellioUtils
|
|
5
5
|
extend self
|
6
6
|
|
7
7
|
HandledConstaintError = Class.new(StandardError)
|
8
|
+
InvalidPkError = Class.new(StandardError)
|
8
9
|
|
9
10
|
def handle_constraint_error(constraint_name, &block)
|
10
11
|
DB.transaction(savepoint: true, &block)
|
@@ -22,7 +23,7 @@ module UmbrellioUtils
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def each_record(dataset, **options, &block)
|
25
|
-
primary_key = primary_key_from(**options)
|
26
|
+
primary_key = primary_key_from(dataset, **options)
|
26
27
|
|
27
28
|
with_temp_table(dataset, **options) do |ids|
|
28
29
|
rows = ids.map { |id| row(id.is_a?(Hash) ? id.values : [id]) }
|
@@ -31,7 +32,7 @@ module UmbrellioUtils
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def with_temp_table(dataset, page_size: 1_000, sleep: nil, **options)
|
34
|
-
primary_key = primary_key_from(**options)
|
35
|
+
primary_key = primary_key_from(dataset, **options)
|
35
36
|
sleep_interval = sleep_interval_from(sleep)
|
36
37
|
|
37
38
|
temp_table_name = create_temp_table(dataset, primary_key: primary_key)
|
@@ -62,7 +63,7 @@ module UmbrellioUtils
|
|
62
63
|
time = Time.current
|
63
64
|
model = dataset.model
|
64
65
|
temp_table_name = "temp_#{model.table_name}_#{time.to_i}_#{time.nsec}".to_sym
|
65
|
-
primary_key = primary_key_from(**options)
|
66
|
+
primary_key = primary_key_from(dataset, **options)
|
66
67
|
|
67
68
|
DB.create_table(temp_table_name, unlogged: true) do
|
68
69
|
primary_key.each do |field|
|
@@ -85,8 +86,14 @@ module UmbrellioUtils
|
|
85
86
|
Sequel.function(:row, *values)
|
86
87
|
end
|
87
88
|
|
88
|
-
def
|
89
|
-
|
89
|
+
def extract_primary_key(dataset)
|
90
|
+
dataset.db.schema(dataset.first_source).select { |x| x[1][:primary_key] }.map(&:first)
|
91
|
+
end
|
92
|
+
|
93
|
+
def primary_key_from(dataset, **options)
|
94
|
+
Array(options[:primary_key] || extract_primary_key(dataset)).tap do |primary_key|
|
95
|
+
raise InvalidPkError if primary_key.empty?
|
96
|
+
end
|
90
97
|
end
|
91
98
|
|
92
99
|
def qualified_pk(table_name, primary_key)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umbrellio-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Team Umbrellio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: memery
|