kiba-plus 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0828c6c1f68719602e7da95022b0903b04ec26de2aef90b5a3ed965cdf4c803a'
|
4
|
+
data.tar.gz: 015ce68daf808b52dd582d42e15774d5eb4f8d8ed788a407f6cdf6ceece8f9d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e6c4db4898719071ba940b0d0abc9784f4acb84937fb6ae0ae3c3de89f21fc112cb6593d8f5d3b85099b3f107c54084ff6e9b38509673dcf2fc49dcd69d374a
|
7
|
+
data.tar.gz: 9d247bed23b59922a5bc2aa4f6c3e2e42fa22c8acb20dbee46cf8c3595fc4c4b3324916f281633b516dfba477d22ddc82684144c34f6b66a52d5810beff777a1
|
@@ -43,14 +43,15 @@ module Kiba::Plus::Destination
|
|
43
43
|
sql = "TRUNCATE TABLE #{table_name}"
|
44
44
|
format_sql sql
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
|
+
# TODO remove it
|
47
48
|
def delete_before_insert
|
48
49
|
sql = delete_before_insert_sql
|
49
50
|
Kiba::Plus.logger.info sql
|
50
51
|
@conn.exec(sql)
|
51
52
|
end
|
52
53
|
|
53
|
-
# TODO
|
54
|
+
# TODO remove it
|
54
55
|
def delete_before_insert_sql
|
55
56
|
where = Array(unique_by).map{|x| ["#{staging_table_name}.#{x}", "#{table_name}.#{x}"].join(" = ") }.join(" AND ")
|
56
57
|
sql = "DELETE FROM #{table_name} USING #{staging_table_name} WHERE #{where}"
|
@@ -64,7 +65,12 @@ module Kiba::Plus::Destination
|
|
64
65
|
end
|
65
66
|
|
66
67
|
def merge_to_target_table_sql
|
67
|
-
|
68
|
+
sets = columns.map{|x| "#{x} = excluded.#{x}" }.join(', ')
|
69
|
+
sql = <<~SQL
|
70
|
+
INSERT INTO #{table_name} (SELECT * FROM #{staging_table_name})
|
71
|
+
ON CONFLICT (#{unique_by.join(", ")})
|
72
|
+
DO UPDATE SET #{sets}
|
73
|
+
SQL
|
68
74
|
format_sql sql
|
69
75
|
end
|
70
76
|
|
data/lib/kiba/plus/version.rb
CHANGED