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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7aee35c2fa20e158c0dcaf4f72ae6649209016cb
4
- data.tar.gz: f3272a901d950df4c9b8846a5fa13e004490e4e8
3
+ metadata.gz: 930bb93fc7cdf5236b363f9f1f343e400f567e92
4
+ data.tar.gz: bc4abbac8eedc26e82b4599ce80657ad99dacab5
5
5
  SHA512:
6
- metadata.gz: 8ce44faf6d367af7b9b8e7546991a758f984310c7de2916726782992e0ddcb4e33c13d0c24cab684cfd5cc9a532901859e6110af060b035fd13240e05e284c78
7
- data.tar.gz: 28a2cc3e5f7d90c5fe8ef8e5de8fc437a5d0eb5fa6c5f91162279095476c6eb57b4e3ee786b6a89da5cc0c031762cfce0a91b362b87bcc73fe12c73a232eb510
6
+ metadata.gz: 672c4a3ed57a3b3d2de8cb996fddfc0819da3de23af2dbdf6fdb6c962f4d2a5eda7e773e2e8768be403ed0643dd620124e0c3ac8f9c1e841e54d44d7887b0757
7
+ data.tar.gz: 9c0573d506286947956602885042246478f1798ba82622f5574f959a7eca5b2eba4487de670cf3655d2ee50365011f487bca2b506c076fd8f0edf95045f54689
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v1.3.5 2017-10-12
2
+
3
+ ### Changed
4
+
5
+ * Added compatibility with `dry-types` 0.11 (flash-gordon)
6
+
7
+ [Compare v1.3.4..v1.3.5](https://github.com/rom-rb/rom-sql/compare/v1.3.4...v1.3.5)
8
+
1
9
  ## v1.3.4 2017-09-12
2
10
 
3
11
  ### Fixed
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
  gem 'rom', git: 'https://github.com/rom-rb/rom.git', branch: 'release-3.0'
6
6
 
7
7
  group :test do
8
- gem 'byebug', platforms: :mri
8
+ gem 'pry-byebug', platforms: :mri
9
9
  gem 'pry', platforms: %i(jruby rbx)
10
10
  gem 'dry-struct'
11
11
  gem 'activesupport', '~> 5.0'
@@ -28,9 +28,10 @@ module ROM
28
28
  # @return [Hash]
29
29
  #
30
30
  # @api public
31
- def [](type)
32
- unwrapped = type.optional? ? type.right : type
33
- @types[unwrapped.pristine] || EMPTY_HASH
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
- @types[type] = functions
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
- Array.constructor(-> (v) { Sequel.pg_array(v, db_type) }).meta(type: db_type)
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
- Attribute::TypeExtensions.register(Array.constructor -> { }) do
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
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module SQL
3
- VERSION = '1.3.4'.freeze
3
+ VERSION = '1.3.5'.freeze
4
4
  end
5
5
  end
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.10.2'
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('biging').optional.meta(name: :tag_ids, source: source),
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
@@ -21,7 +21,7 @@ require 'logger'
21
21
  require 'tempfile'
22
22
 
23
23
  begin
24
- require 'byebug'
24
+ require 'pry-byebug'
25
25
  rescue LoadError
26
26
  require 'pry'
27
27
  end
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
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-09-12 00:00:00.000000000 Z
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.10.2
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.10.2
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.11
348
+ rubygems_version: 2.6.13
349
349
  signing_key:
350
350
  specification_version: 4
351
351
  summary: SQL databases support for ROM