rom-sql 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -1
- data/lib/rom/sql/attribute.rb +11 -5
- data/lib/rom/sql/extensions/postgres/inferrer.rb +1 -1
- data/lib/rom/sql/extensions/postgres/types.rb +16 -4
- data/lib/rom/sql/version.rb +1 -1
- data/rom-sql.gemspec +1 -1
- data/spec/integration/schema/inferrer/postgres_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 930bb93fc7cdf5236b363f9f1f343e400f567e92
|
4
|
+
data.tar.gz: bc4abbac8eedc26e82b4599ce80657ad99dacab5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 672c4a3ed57a3b3d2de8cb996fddfc0819da3de23af2dbdf6fdb6c962f4d2a5eda7e773e2e8768be403ed0643dd620124e0c3ac8f9c1e841e54d44d7887b0757
|
7
|
+
data.tar.gz: 9c0573d506286947956602885042246478f1798ba82622f5574f959a7eca5b2eba4487de670cf3655d2ee50365011f487bca2b506c076fd8f0edf95045f54689
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/lib/rom/sql/attribute.rb
CHANGED
@@ -28,9 +28,10 @@ module ROM
|
|
28
28
|
# @return [Hash]
|
29
29
|
#
|
30
30
|
# @api public
|
31
|
-
def [](
|
32
|
-
|
33
|
-
|
31
|
+
def [](wrapped)
|
32
|
+
type = wrapped.default? ? wrapped.type : wrapped
|
33
|
+
type = type.optional? ? type.right : type
|
34
|
+
@types[type.meta[:database]][type.meta[:db_type]] || EMPTY_HASH
|
34
35
|
end
|
35
36
|
|
36
37
|
# Registers a set of operations supported for a specific type
|
@@ -46,15 +47,20 @@ module ROM
|
|
46
47
|
#
|
47
48
|
# @api public
|
48
49
|
def register(type, &block)
|
50
|
+
extensions = @types[type.meta[:database]]
|
51
|
+
db_type = type.meta[:db_type]
|
52
|
+
|
49
53
|
raise ArgumentError, "Type #{ type } already registered" if @types.key?(type)
|
50
54
|
mod = Module.new(&block)
|
51
55
|
ctx = Object.new.extend(mod)
|
52
56
|
functions = mod.public_instance_methods.each_with_object({}) { |m, ms| ms[m] = ctx.method(m) }
|
53
|
-
|
57
|
+
extensions[db_type] = functions
|
54
58
|
end
|
55
59
|
end
|
56
60
|
|
57
|
-
@types =
|
61
|
+
@types = ::Hash.new do |hash, database|
|
62
|
+
hash[database] = {}
|
63
|
+
end
|
58
64
|
end
|
59
65
|
|
60
66
|
extend Dry::Core::Cache
|
@@ -50,7 +50,7 @@ module ROM
|
|
50
50
|
|
51
51
|
def map_type(ruby_type, db_type, enum_values: nil, **_)
|
52
52
|
if db_type.end_with?(self.class.db_array_type_matcher)
|
53
|
-
Types::PG::Array(db_type)
|
53
|
+
Types::PG::Array(db_type[0...db_type.size-2])
|
54
54
|
elsif enum_values
|
55
55
|
Types::String.enum(*enum_values)
|
56
56
|
else
|
@@ -16,8 +16,16 @@ module ROM
|
|
16
16
|
|
17
17
|
Array = Types.Definition(Sequel::Postgres::PGArray)
|
18
18
|
|
19
|
+
@array_types = ::Hash.new do |hash, type|
|
20
|
+
name = "#{ type }[]"
|
21
|
+
array_type = Array.constructor(-> (v) { Sequel.pg_array(v, type) }).
|
22
|
+
meta(type: name, db_type: name, database: 'postgres')
|
23
|
+
Attribute::TypeExtensions.register(array_type) { include ArrayMethods }
|
24
|
+
hash[type] = array_type
|
25
|
+
end
|
26
|
+
|
19
27
|
def self.Array(db_type)
|
20
|
-
|
28
|
+
@array_types[db_type]
|
21
29
|
end
|
22
30
|
|
23
31
|
# @!parse
|
@@ -109,7 +117,7 @@ module ROM
|
|
109
117
|
# #
|
110
118
|
# # @api public
|
111
119
|
# end
|
112
|
-
|
120
|
+
module ArrayMethods
|
113
121
|
def contain(type, expr, other)
|
114
122
|
Attribute[Types::Bool].meta(sql_expr: expr.pg_array.contains(type[other]))
|
115
123
|
end
|
@@ -147,6 +155,10 @@ module ROM
|
|
147
155
|
end
|
148
156
|
end
|
149
157
|
|
158
|
+
Attribute::TypeExtensions.register(Array.constructor -> { }) do
|
159
|
+
include ArrayMethods
|
160
|
+
end
|
161
|
+
|
150
162
|
# JSON
|
151
163
|
|
152
164
|
JSONArray = Types.Constructor(Sequel::Postgres::JSONArray, &Sequel.method(:pg_json))
|
@@ -155,7 +167,7 @@ module ROM
|
|
155
167
|
|
156
168
|
JSONOp = Types.Constructor(Sequel::Postgres::JSONOp, &Sequel.method(:pg_json))
|
157
169
|
|
158
|
-
JSON = JSONArray | JSONHash | JSONOp
|
170
|
+
JSON = (JSONArray | JSONHash | JSONOp).meta(database: 'postgres', db_type: 'jsonb')
|
159
171
|
|
160
172
|
# JSONB
|
161
173
|
|
@@ -165,7 +177,7 @@ module ROM
|
|
165
177
|
|
166
178
|
JSONBOp = Types.Constructor(Sequel::Postgres::JSONBOp, &Sequel.method(:pg_jsonb))
|
167
179
|
|
168
|
-
JSONB = JSONBArray | JSONBHash | JSONBOp
|
180
|
+
JSONB = (JSONBArray | JSONBHash | JSONBOp).meta(database: 'postgres', db_type: 'jsonb')
|
169
181
|
|
170
182
|
# @!parse
|
171
183
|
# class ROM::SQL::Attribute
|
data/lib/rom/sql/version.rb
CHANGED
data/rom-sql.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_runtime_dependency 'sequel', '~> 4.43'
|
21
21
|
spec.add_runtime_dependency 'dry-equalizer', '~> 0.2'
|
22
|
-
spec.add_runtime_dependency 'dry-types', '~> 0.
|
22
|
+
spec.add_runtime_dependency 'dry-types', '~> 0.11.0'
|
23
23
|
spec.add_runtime_dependency 'dry-core', '~> 0.3'
|
24
24
|
spec.add_runtime_dependency 'rom', '~> 3.2', '>= 3.2.2'
|
25
25
|
|
@@ -63,7 +63,7 @@ RSpec.describe 'ROM::SQL::Schema::PostgresInferrer', :postgres do
|
|
63
63
|
jsonb_data: ROM::SQL::Types::PG::JSONB.optional.meta(name: :jsonb_data, source: source),
|
64
64
|
money: ROM::SQL::Types::Decimal.meta(name: :money, source: source),
|
65
65
|
tags: ROM::SQL::Types::PG::Array('text').optional.meta(name: :tags, source: source),
|
66
|
-
tag_ids: ROM::SQL::Types::PG::Array('
|
66
|
+
tag_ids: ROM::SQL::Types::PG::Array('bigint').optional.meta(name: :tag_ids, source: source),
|
67
67
|
color: ROM::SQL::Types::String.enum(*colors).optional.meta(name: :color, source: source),
|
68
68
|
ip: ROM::SQL::Types::PG::IPAddress.optional.meta(
|
69
69
|
name: :ip,
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.11.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.11.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: dry-core
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -345,7 +345,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
345
345
|
version: '0'
|
346
346
|
requirements: []
|
347
347
|
rubyforge_project:
|
348
|
-
rubygems_version: 2.6.
|
348
|
+
rubygems_version: 2.6.13
|
349
349
|
signing_key:
|
350
350
|
specification_version: 4
|
351
351
|
summary: SQL databases support for ROM
|