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: b92d471a5e4b16eb461128e8fce8c650f1168bdd566d8dc86f088a2588b04ba6
4
- data.tar.gz: 47968f523c74c2649a590ffac8ff065820602ee6b322c9488306305522a4a605
3
+ metadata.gz: '0828c6c1f68719602e7da95022b0903b04ec26de2aef90b5a3ed965cdf4c803a'
4
+ data.tar.gz: 015ce68daf808b52dd582d42e15774d5eb4f8d8ed788a407f6cdf6ceece8f9d5
5
5
  SHA512:
6
- metadata.gz: 1c5a75e3efea8461564b4e26d7d65c44bdef7ffee8941e53471e9be3aa4423debb3b278148ea49861c15481942f3509bbff8af10df7355e6c8bfb3f37fe383e8
7
- data.tar.gz: 76e13f396303c0b0c7552cafe3a72f14badd54fc77af900d13726ae49f8f4db584d099d0eec6331f96a396201dbacd7a792a59ff5efdedac2bfe505855f37d33
6
+ metadata.gz: 8e6c4db4898719071ba940b0d0abc9784f4acb84937fb6ae0ae3c3de89f21fc112cb6593d8f5d3b85099b3f107c54084ff6e9b38509673dcf2fc49dcd69d374a
7
+ data.tar.gz: 9d247bed23b59922a5bc2aa4f6c3e2e42fa22c8acb20dbee46cf8c3595fc4c4b3324916f281633b516dfba477d22ddc82684144c34f6b66a52d5810beff777a1
@@ -32,7 +32,7 @@ module Kiba::Plus::Destination
32
32
  drop_staging_table
33
33
  create_staging_table
34
34
  copy_to_staging_table
35
- delete_before_insert
35
+ #delete_before_insert
36
36
  merge_to_target_table
37
37
  drop_staging_table
38
38
  else
@@ -44,7 +44,7 @@ module Kiba::Plus::Destination
44
44
  @conn.put_copy_end
45
45
  @conn.get_last_result
46
46
  if incremental
47
- delete_before_insert
47
+ #delete_before_insert
48
48
  merge_to_target_table
49
49
  drop_staging_table
50
50
  end
@@ -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 add where condition to speed up deleting.
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
- sql = "INSERT INTO #{table_name} (SELECT * FROM #{staging_table_name})"
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
 
@@ -1,5 +1,5 @@
1
1
  module Kiba
2
2
  module Plus
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiba-plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hooopo