relationizer 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/relationizer/big_query/standard.rb +23 -17
- data/lib/relationizer/postgresql.rb +24 -12
- data/lib/relationizer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48cac1b36f04f43929750f209e07f9e2bda3c0ce
|
4
|
+
data.tar.gz: ae607d94583019150e2b0bd5961cb5d90a351143
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4f8034c808c4dbecad7aa1ec1f13135b5b41090d4129a65b7531fb82d669b8ba226649f9890d97865f4502ba6c0b21cae64f1802e96cde8f5973b593f0382f8
|
7
|
+
data.tar.gz: 2a71e9995be92db05ea108977384484f6565b9b16c4e39ee3262c2dbee340cec0478bde738ed80704911262089e0c1dc559bd8183452e29dd7efc52dcee8ebc6
|
@@ -6,17 +6,23 @@ module Relationizer
|
|
6
6
|
module Standard
|
7
7
|
class ReasonlessTypeError < StandardError; end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
KNOWN_TYPES = [:INT64, :FLOAT64, :STRING, :BOOL, :TIMESTAMP, :DATE]
|
10
|
+
|
11
|
+
DEFAULT_TYPES = -> (obj) {
|
12
|
+
case obj
|
13
|
+
when Integer then :INT64
|
14
|
+
when BigDecimal then :FLOAT64
|
15
|
+
when Float then :FLOAT64
|
16
|
+
when String then :STRING
|
17
|
+
when TrueClass then :BOOL
|
18
|
+
when FalseClass then :BOOL
|
19
|
+
when Time then :TIMESTAMP
|
20
|
+
when DateTime then :TIMESTAMP
|
21
|
+
when Date then :DATE
|
22
|
+
when Array then :ARRAY
|
23
|
+
else
|
24
|
+
nil
|
25
|
+
end
|
20
26
|
}
|
21
27
|
|
22
28
|
def create_relation_literal(schema, tuples)
|
@@ -49,7 +55,7 @@ module Relationizer
|
|
49
55
|
raise ReasonlessTypeError.new("Ambiguous type of element in array: #{classes}")
|
50
56
|
end
|
51
57
|
|
52
|
-
DEFAULT_TYPES[
|
58
|
+
DEFAULT_TYPES[array.first] || :STRING
|
53
59
|
end
|
54
60
|
|
55
61
|
def types_exp(names, types)
|
@@ -76,16 +82,16 @@ module Relationizer
|
|
76
82
|
if values.map { |o| o.is_a?(Array) }.all?
|
77
83
|
types = values.
|
78
84
|
map(&method(:array_type)).uniq.
|
79
|
-
tap(&method(:
|
80
|
-
tap(&method(:
|
85
|
+
tap(&method(:empty_candidate_check)).
|
86
|
+
tap(&method(:many_candidate_check))
|
81
87
|
|
82
88
|
next "ARRAY<#{types.first}>".to_sym
|
83
89
|
end
|
84
90
|
|
85
|
-
values.
|
91
|
+
values.
|
86
92
|
map(&DEFAULT_TYPES).compact.uniq.
|
87
|
-
tap(&method(:many_candidate_check)).
|
88
93
|
tap(&method(:empty_candidate_check)).
|
94
|
+
tap(&method(:many_candidate_check)).
|
89
95
|
first || :STRING
|
90
96
|
}
|
91
97
|
end
|
@@ -99,7 +105,7 @@ module Relationizer
|
|
99
105
|
obj.map { |e| to_literal(e, t) }.join(', ').tap { |s| break "[#{s}]"}
|
100
106
|
when /^ARRAY\<.+\>$/
|
101
107
|
t = /^ARRAY\<(.+)\>$/.match(type).to_a&.dig(1).to_sym
|
102
|
-
raise "Unknown type: #{t}" unless
|
108
|
+
raise "Unknown type: #{t}" unless KNOWN_TYPES.include?(t)
|
103
109
|
obj.map { |e| to_literal(e, t) }.join(', ').tap { |s| break "[#{s}]"}
|
104
110
|
when :TIMESTAMP
|
105
111
|
%Q{'#{obj.strftime('%Y-%m-%d %H:%M:%S')}'}
|
@@ -5,16 +5,29 @@ module Relationizer
|
|
5
5
|
module Postgresql
|
6
6
|
class ReasonlessTypeError < StandardError; end
|
7
7
|
|
8
|
-
DEFAULT_TYPES = {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
DEFAULT_TYPES = -> (obj) {
|
9
|
+
case obj
|
10
|
+
when Integer
|
11
|
+
:INT8
|
12
|
+
when BigDecimal
|
13
|
+
:DECIMAL
|
14
|
+
when Float
|
15
|
+
:FLOAT8
|
16
|
+
when String
|
17
|
+
:TEXT
|
18
|
+
when TrueClass
|
19
|
+
:BOOLEAN
|
20
|
+
when FalseClass
|
21
|
+
:BOOLEAN
|
22
|
+
when Time
|
23
|
+
:TIMESTAMPTZ
|
24
|
+
when DateTime
|
25
|
+
:TIMESTAMPTZ
|
26
|
+
when Date
|
27
|
+
:DATE
|
28
|
+
else
|
29
|
+
nil
|
30
|
+
end
|
18
31
|
}
|
19
32
|
|
20
33
|
def create_relation_literal(schema, tuples)
|
@@ -39,10 +52,9 @@ module Relationizer
|
|
39
52
|
next "#{name}::#{type.to_s.upcase}" if type
|
40
53
|
|
41
54
|
values.
|
42
|
-
map(&:class).uniq.
|
43
55
|
map(&DEFAULT_TYPES).compact.uniq.
|
44
|
-
tap(&method(:many_candidate_check)).
|
45
56
|
tap(&method(:empty_candidate_check)).
|
57
|
+
tap(&method(:many_candidate_check)).
|
46
58
|
first.
|
47
59
|
to_s.upcase.
|
48
60
|
tap { |fixed_type| break "#{name}::#{fixed_type}" }
|
data/lib/relationizer/version.rb
CHANGED