db_memoize 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/db_memoize/value.rb +17 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 104a42e53e91c5485d2babe2f22995633965025b6a9bf4790b54d1e7768aef45
4
- data.tar.gz: 0301ec4568f6787036176431fbdaa327c7e564287b06b670ddc95396672f79fc
3
+ metadata.gz: 520170b67792fdb3910895e3c510d6085cbd8666a306d357fdbd61236981c958
4
+ data.tar.gz: 921d0f58c8757bfc145132e95495f444d8d10cabc3fef247ae945faecc84e883
5
5
  SHA512:
6
- metadata.gz: 0fc1493d08f64346c0bc7cb9ff1da76ac0d6a32e6d7c9a42fc56e39f2cf174ab1c18f668410b3fd0015405847aa4cb204605028b41d0c71c13c93830157ec18d
7
- data.tar.gz: 73d3a582bb4544a3c813794abe13e1aea4f6c40d298de3808ab648be76280c712fbbf2451061dc043d1fa4cb4e384450eeaf6fdbf70b5b1ce1871392388439ea
6
+ metadata.gz: 356ede40ddf8a75be14043d01fa83fad462c6df3adc0c28db8a18a866276fdbd7b51c9ad8aef7e6236215f6f623fdbdde5575f987bb46807ddbe425e81e1a12e
7
+ data.tar.gz: 4c386fbe295073209a55ebac0ff4e03ac97037810fa7b42d7690ce7c4d05f92727887f00e7a9f2045e865b157ad7026607a6899d305d57381437f583c9304e3e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.8
1
+ 0.3.9
@@ -81,17 +81,34 @@ module DbMemoize
81
81
  end
82
82
  end
83
83
 
84
+ ALL_COLUMNS = [
85
+ :val_string,
86
+ :val_integer,
87
+ :val_float,
88
+ :val_time,
89
+ :val_object,
90
+ :val_boolean,
91
+ :val_nil
92
+ ].freeze
93
+
84
94
  def self.simple_sql_create_value(column, entity_table_name:, entity_id:, method_name:, value:)
95
+ other_columns = ALL_COLUMNS - [column]
96
+ default_updates = other_columns.map { |c| "#{c}=NULL" }
97
+
85
98
  sql = <<~SQL.freeze
86
99
  INSERT INTO #{table_name}
87
100
  (entity_table_name, entity_id, method_name, #{column}, created_at)
88
101
  VALUES($1,$2,$3,$4,NOW())
102
+ ON CONFLICT (entity_id, entity_table_name, method_name)
103
+ DO UPDATE
104
+ SET #{default_updates.join(', ')}, #{column}=$4, created_at=NOW()
89
105
  SQL
90
106
 
91
107
  SQL.ask sql, entity_table_name, entity_id, method_name, value
92
108
  end
93
109
 
94
110
  def self.ar_create_value(column, entity_table_name:, entity_id:, method_name:, value:)
111
+ # [TODO] this code is not resolving conflicts on the unique index.
95
112
  data = {
96
113
  :entity_table_name => entity_table_name,
97
114
  :entity_id => entity_id,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: db_memoize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - johannes-kostas goetzinger
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-24 00:00:00.000000000 Z
11
+ date: 2018-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple-sql