activerecord-materialize-adapter 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/materialize/column.rb +0 -9
- data/lib/active_record/connection_adapters/materialize/database_statements.rb +22 -41
- data/lib/active_record/connection_adapters/materialize/oid.rb +0 -12
- data/lib/active_record/connection_adapters/materialize/oid/type_map_initializer.rb +5 -48
- data/lib/active_record/connection_adapters/materialize/quoting.rb +1 -7
- data/lib/active_record/connection_adapters/materialize/schema/source_statements.rb +66 -0
- data/lib/active_record/connection_adapters/materialize/schema/view_statements.rb +22 -0
- data/lib/active_record/connection_adapters/materialize/schema_creation.rb +18 -53
- data/lib/active_record/connection_adapters/materialize/schema_definitions.rb +3 -6
- data/lib/active_record/connection_adapters/materialize/schema_dumper.rb +82 -22
- data/lib/active_record/connection_adapters/materialize/schema_statements.rb +102 -354
- data/lib/active_record/connection_adapters/materialize/version.rb +1 -1
- data/lib/active_record/connection_adapters/materialize_adapter.rb +100 -253
- metadata +9 -15
- data/lib/active_record/connection_adapters/materialize/oid/cidr.rb +0 -50
- data/lib/active_record/connection_adapters/materialize/oid/legacy_point.rb +0 -44
- data/lib/active_record/connection_adapters/materialize/oid/money.rb +0 -41
- data/lib/active_record/connection_adapters/materialize/oid/point.rb +0 -64
- data/lib/active_record/connection_adapters/materialize/oid/range.rb +0 -96
- data/lib/active_record/connection_adapters/materialize/oid/uuid.rb +0 -25
- data/lib/active_record/connection_adapters/materialize/oid/vector.rb +0 -28
- data/lib/active_record/connection_adapters/materialize/oid/xml.rb +0 -30
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-materialize-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henry Tseng
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.1'
|
48
|
-
type: :
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
@@ -111,7 +111,6 @@ files:
|
|
111
111
|
- lib/active_record/connection_adapters/materialize/oid/bit.rb
|
112
112
|
- lib/active_record/connection_adapters/materialize/oid/bit_varying.rb
|
113
113
|
- lib/active_record/connection_adapters/materialize/oid/bytea.rb
|
114
|
-
- lib/active_record/connection_adapters/materialize/oid/cidr.rb
|
115
114
|
- lib/active_record/connection_adapters/materialize/oid/date.rb
|
116
115
|
- lib/active_record/connection_adapters/materialize/oid/date_time.rb
|
117
116
|
- lib/active_record/connection_adapters/materialize/oid/decimal.rb
|
@@ -119,18 +118,13 @@ files:
|
|
119
118
|
- lib/active_record/connection_adapters/materialize/oid/hstore.rb
|
120
119
|
- lib/active_record/connection_adapters/materialize/oid/inet.rb
|
121
120
|
- lib/active_record/connection_adapters/materialize/oid/jsonb.rb
|
122
|
-
- lib/active_record/connection_adapters/materialize/oid/legacy_point.rb
|
123
|
-
- lib/active_record/connection_adapters/materialize/oid/money.rb
|
124
121
|
- lib/active_record/connection_adapters/materialize/oid/oid.rb
|
125
|
-
- lib/active_record/connection_adapters/materialize/oid/point.rb
|
126
|
-
- lib/active_record/connection_adapters/materialize/oid/range.rb
|
127
122
|
- lib/active_record/connection_adapters/materialize/oid/specialized_string.rb
|
128
123
|
- lib/active_record/connection_adapters/materialize/oid/type_map_initializer.rb
|
129
|
-
- lib/active_record/connection_adapters/materialize/oid/uuid.rb
|
130
|
-
- lib/active_record/connection_adapters/materialize/oid/vector.rb
|
131
|
-
- lib/active_record/connection_adapters/materialize/oid/xml.rb
|
132
124
|
- lib/active_record/connection_adapters/materialize/quoting.rb
|
133
125
|
- lib/active_record/connection_adapters/materialize/referential_integrity.rb
|
126
|
+
- lib/active_record/connection_adapters/materialize/schema/source_statements.rb
|
127
|
+
- lib/active_record/connection_adapters/materialize/schema/view_statements.rb
|
134
128
|
- lib/active_record/connection_adapters/materialize/schema_creation.rb
|
135
129
|
- lib/active_record/connection_adapters/materialize/schema_definitions.rb
|
136
130
|
- lib/active_record/connection_adapters/materialize/schema_dumper.rb
|
@@ -148,7 +142,7 @@ licenses:
|
|
148
142
|
- MIT
|
149
143
|
metadata:
|
150
144
|
source_code_uri: https://github.com/henrytseng/activerecord-materialize-adapter
|
151
|
-
post_install_message:
|
145
|
+
post_install_message:
|
152
146
|
rdoc_options: []
|
153
147
|
require_paths:
|
154
148
|
- lib
|
@@ -163,8 +157,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
157
|
- !ruby/object:Gem::Version
|
164
158
|
version: '0'
|
165
159
|
requirements: []
|
166
|
-
rubygems_version: 3.0.
|
167
|
-
signing_key:
|
160
|
+
rubygems_version: 3.0.3
|
161
|
+
signing_key:
|
168
162
|
specification_version: 4
|
169
163
|
summary: Database adapter for materialize.io database.
|
170
164
|
test_files: []
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "ipaddr"
|
4
|
-
|
5
|
-
module ActiveRecord
|
6
|
-
module ConnectionAdapters
|
7
|
-
module Materialize
|
8
|
-
module OID # :nodoc:
|
9
|
-
class Cidr < Type::Value # :nodoc:
|
10
|
-
def type
|
11
|
-
:cidr
|
12
|
-
end
|
13
|
-
|
14
|
-
def type_cast_for_schema(value)
|
15
|
-
subnet_mask = value.instance_variable_get(:@mask_addr)
|
16
|
-
|
17
|
-
# If the subnet mask is equal to /32, don't output it
|
18
|
-
if subnet_mask == (2**32 - 1)
|
19
|
-
"\"#{value}\""
|
20
|
-
else
|
21
|
-
"\"#{value}/#{subnet_mask.to_s(2).count('1')}\""
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def serialize(value)
|
26
|
-
if IPAddr === value
|
27
|
-
"#{value}/#{value.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
|
28
|
-
else
|
29
|
-
value
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def cast_value(value)
|
34
|
-
if value.nil?
|
35
|
-
nil
|
36
|
-
elsif String === value
|
37
|
-
begin
|
38
|
-
IPAddr.new(value)
|
39
|
-
rescue ArgumentError
|
40
|
-
nil
|
41
|
-
end
|
42
|
-
else
|
43
|
-
value
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module ConnectionAdapters
|
5
|
-
module Materialize
|
6
|
-
module OID # :nodoc:
|
7
|
-
class LegacyPoint < Type::Value # :nodoc:
|
8
|
-
include ActiveModel::Type::Helpers::Mutable
|
9
|
-
|
10
|
-
def type
|
11
|
-
:point
|
12
|
-
end
|
13
|
-
|
14
|
-
def cast(value)
|
15
|
-
case value
|
16
|
-
when ::String
|
17
|
-
if value[0] == "(" && value[-1] == ")"
|
18
|
-
value = value[1...-1]
|
19
|
-
end
|
20
|
-
cast(value.split(","))
|
21
|
-
when ::Array
|
22
|
-
value.map { |v| Float(v) }
|
23
|
-
else
|
24
|
-
value
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def serialize(value)
|
29
|
-
if value.is_a?(::Array)
|
30
|
-
"(#{number_for_point(value[0])},#{number_for_point(value[1])})"
|
31
|
-
else
|
32
|
-
super
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
def number_for_point(number)
|
38
|
-
number.to_s.gsub(/\.0$/, "")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module ConnectionAdapters
|
5
|
-
module Materialize
|
6
|
-
module OID # :nodoc:
|
7
|
-
class Money < Type::Decimal # :nodoc:
|
8
|
-
def type
|
9
|
-
:money
|
10
|
-
end
|
11
|
-
|
12
|
-
def scale
|
13
|
-
2
|
14
|
-
end
|
15
|
-
|
16
|
-
def cast_value(value)
|
17
|
-
return value unless ::String === value
|
18
|
-
|
19
|
-
# Because money output is formatted according to the locale, there are two
|
20
|
-
# cases to consider (note the decimal separators):
|
21
|
-
# (1) $12,345,678.12
|
22
|
-
# (2) $12.345.678,12
|
23
|
-
# Negative values are represented as follows:
|
24
|
-
# (3) -$2.55
|
25
|
-
# (4) ($2.55)
|
26
|
-
|
27
|
-
value = value.sub(/^\((.+)\)$/, '-\1') # (4)
|
28
|
-
case value
|
29
|
-
when /^-?\D*+[\d,]+\.\d{2}$/ # (1)
|
30
|
-
value.gsub!(/[^-\d.]/, "")
|
31
|
-
when /^-?\D*+[\d.]+,\d{2}$/ # (2)
|
32
|
-
value.gsub!(/[^-\d,]/, "").sub!(/,/, ".")
|
33
|
-
end
|
34
|
-
|
35
|
-
super(value)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
Point = Struct.new(:x, :y)
|
5
|
-
|
6
|
-
module ConnectionAdapters
|
7
|
-
module Materialize
|
8
|
-
module OID # :nodoc:
|
9
|
-
class Point < Type::Value # :nodoc:
|
10
|
-
include ActiveModel::Type::Helpers::Mutable
|
11
|
-
|
12
|
-
def type
|
13
|
-
:point
|
14
|
-
end
|
15
|
-
|
16
|
-
def cast(value)
|
17
|
-
case value
|
18
|
-
when ::String
|
19
|
-
return if value.blank?
|
20
|
-
|
21
|
-
if value[0] == "(" && value[-1] == ")"
|
22
|
-
value = value[1...-1]
|
23
|
-
end
|
24
|
-
x, y = value.split(",")
|
25
|
-
build_point(x, y)
|
26
|
-
when ::Array
|
27
|
-
build_point(*value)
|
28
|
-
else
|
29
|
-
value
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def serialize(value)
|
34
|
-
case value
|
35
|
-
when ActiveRecord::Point
|
36
|
-
"(#{number_for_point(value.x)},#{number_for_point(value.y)})"
|
37
|
-
when ::Array
|
38
|
-
serialize(build_point(*value))
|
39
|
-
else
|
40
|
-
super
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def type_cast_for_schema(value)
|
45
|
-
if ActiveRecord::Point === value
|
46
|
-
[value.x, value.y]
|
47
|
-
else
|
48
|
-
super
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
def number_for_point(number)
|
54
|
-
number.to_s.gsub(/\.0$/, "")
|
55
|
-
end
|
56
|
-
|
57
|
-
def build_point(x, y)
|
58
|
-
ActiveRecord::Point.new(Float(x), Float(y))
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module ConnectionAdapters
|
5
|
-
module Materialize
|
6
|
-
module OID # :nodoc:
|
7
|
-
class Range < Type::Value # :nodoc:
|
8
|
-
attr_reader :subtype, :type
|
9
|
-
delegate :user_input_in_time_zone, to: :subtype
|
10
|
-
|
11
|
-
def initialize(subtype, type = :range)
|
12
|
-
@subtype = subtype
|
13
|
-
@type = type
|
14
|
-
end
|
15
|
-
|
16
|
-
def type_cast_for_schema(value)
|
17
|
-
value.inspect.gsub("Infinity", "::Float::INFINITY")
|
18
|
-
end
|
19
|
-
|
20
|
-
def cast_value(value)
|
21
|
-
return if value == "empty"
|
22
|
-
return value unless value.is_a?(::String)
|
23
|
-
|
24
|
-
extracted = extract_bounds(value)
|
25
|
-
from = type_cast_single extracted[:from]
|
26
|
-
to = type_cast_single extracted[:to]
|
27
|
-
|
28
|
-
if !infinity?(from) && extracted[:exclude_start]
|
29
|
-
raise ArgumentError, "The Ruby Range object does not support excluding the beginning of a Range. (unsupported value: '#{value}')"
|
30
|
-
end
|
31
|
-
::Range.new(from, to, extracted[:exclude_end])
|
32
|
-
end
|
33
|
-
|
34
|
-
def serialize(value)
|
35
|
-
if value.is_a?(::Range)
|
36
|
-
from = type_cast_single_for_database(value.begin)
|
37
|
-
to = type_cast_single_for_database(value.end)
|
38
|
-
::Range.new(from, to, value.exclude_end?)
|
39
|
-
else
|
40
|
-
super
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def ==(other)
|
45
|
-
other.is_a?(Range) &&
|
46
|
-
other.subtype == subtype &&
|
47
|
-
other.type == type
|
48
|
-
end
|
49
|
-
|
50
|
-
def map(value) # :nodoc:
|
51
|
-
new_begin = yield(value.begin)
|
52
|
-
new_end = yield(value.end)
|
53
|
-
::Range.new(new_begin, new_end, value.exclude_end?)
|
54
|
-
end
|
55
|
-
|
56
|
-
def force_equality?(value)
|
57
|
-
value.is_a?(::Range)
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
def type_cast_single(value)
|
62
|
-
infinity?(value) ? value : @subtype.deserialize(value)
|
63
|
-
end
|
64
|
-
|
65
|
-
def type_cast_single_for_database(value)
|
66
|
-
infinity?(value) ? value : @subtype.serialize(@subtype.cast(value))
|
67
|
-
end
|
68
|
-
|
69
|
-
def extract_bounds(value)
|
70
|
-
from, to = value[1..-2].split(",")
|
71
|
-
{
|
72
|
-
from: (value[1] == "," || from == "-infinity") ? infinity(negative: true) : from,
|
73
|
-
to: (value[-2] == "," || to == "infinity") ? infinity : to,
|
74
|
-
exclude_start: (value[0] == "("),
|
75
|
-
exclude_end: (value[-1] == ")")
|
76
|
-
}
|
77
|
-
end
|
78
|
-
|
79
|
-
def infinity(negative: false)
|
80
|
-
if subtype.respond_to?(:infinity)
|
81
|
-
subtype.infinity(negative: negative)
|
82
|
-
elsif negative
|
83
|
-
-::Float::INFINITY
|
84
|
-
else
|
85
|
-
::Float::INFINITY
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def infinity?(value)
|
90
|
-
value.respond_to?(:infinite?) && value.infinite?
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module ConnectionAdapters
|
5
|
-
module Materialize
|
6
|
-
module OID # :nodoc:
|
7
|
-
class Uuid < Type::Value # :nodoc:
|
8
|
-
ACCEPTABLE_UUID = %r{\A(\{)?([a-fA-F0-9]{4}-?){8}(?(1)\}|)\z}
|
9
|
-
|
10
|
-
alias_method :serialize, :deserialize
|
11
|
-
|
12
|
-
def type
|
13
|
-
:uuid
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
def cast_value(value)
|
18
|
-
casted = value.to_s
|
19
|
-
casted if casted.match?(ACCEPTABLE_UUID)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module ConnectionAdapters
|
5
|
-
module Materialize
|
6
|
-
module OID # :nodoc:
|
7
|
-
class Vector < Type::Value # :nodoc:
|
8
|
-
attr_reader :delim, :subtype
|
9
|
-
|
10
|
-
# +delim+ corresponds to the `typdelim` column in the pg_types
|
11
|
-
# table. +subtype+ is derived from the `typelem` column in the
|
12
|
-
# pg_types table.
|
13
|
-
def initialize(delim, subtype)
|
14
|
-
@delim = delim
|
15
|
-
@subtype = subtype
|
16
|
-
end
|
17
|
-
|
18
|
-
# FIXME: this should probably split on +delim+ and use +subtype+
|
19
|
-
# to cast the values. Unfortunately, the current Rails behavior
|
20
|
-
# is to just return the string.
|
21
|
-
def cast(value)
|
22
|
-
value
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
module ConnectionAdapters
|
5
|
-
module Materialize
|
6
|
-
module OID # :nodoc:
|
7
|
-
class Xml < Type::String # :nodoc:
|
8
|
-
def type
|
9
|
-
:xml
|
10
|
-
end
|
11
|
-
|
12
|
-
def serialize(value)
|
13
|
-
return unless value
|
14
|
-
Data.new(super)
|
15
|
-
end
|
16
|
-
|
17
|
-
class Data # :nodoc:
|
18
|
-
def initialize(value)
|
19
|
-
@value = value
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_s
|
23
|
-
@value
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|