rom-sql 3.7.0 → 4.0.0.alpha1

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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -65
  3. data/LICENSE +1 -1
  4. data/README.md +3 -2
  5. data/lib/rom/plugins/relation/sql/auto_restrictions.rb +10 -12
  6. data/lib/rom/plugins/relation/sql/default_views.rb +75 -0
  7. data/lib/rom/plugins/relation/sql/instrumentation.rb +8 -17
  8. data/lib/rom/plugins/relation/sql/postgres/explain.rb +5 -5
  9. data/lib/rom/plugins/relation/sql/postgres/full_text_search.rb +20 -37
  10. data/lib/rom/plugins/relation/sql/postgres/streaming.rb +17 -14
  11. data/lib/rom/sql/associations/many_to_many.rb +4 -7
  12. data/lib/rom/sql/associations/many_to_one.rb +3 -6
  13. data/lib/rom/sql/associations/one_to_many.rb +3 -3
  14. data/lib/rom/sql/associations/one_to_one.rb +1 -1
  15. data/lib/rom/sql/associations/one_to_one_through.rb +1 -1
  16. data/lib/rom/sql/associations/self_ref.rb +1 -1
  17. data/lib/rom/sql/associations.rb +5 -5
  18. data/lib/rom/sql/attribute.rb +17 -31
  19. data/lib/rom/sql/attribute_aliasing.rb +4 -6
  20. data/lib/rom/sql/commands/create.rb +5 -5
  21. data/lib/rom/sql/commands/delete.rb +2 -2
  22. data/lib/rom/sql/commands/update.rb +5 -5
  23. data/lib/rom/sql/commands.rb +4 -4
  24. data/lib/rom/sql/dsl.rb +4 -6
  25. data/lib/rom/sql/errors.rb +3 -3
  26. data/lib/rom/sql/extensions/active_support_notifications.rb +3 -3
  27. data/lib/rom/sql/extensions/mysql/type_builder.rb +5 -5
  28. data/lib/rom/sql/extensions/mysql.rb +1 -1
  29. data/lib/rom/sql/extensions/postgres/commands.rb +13 -31
  30. data/lib/rom/sql/extensions/postgres/type_builder.rb +28 -31
  31. data/lib/rom/sql/extensions/postgres/type_serializer.rb +24 -25
  32. data/lib/rom/sql/extensions/postgres/types/array.rb +4 -4
  33. data/lib/rom/sql/extensions/postgres/types/array_types.rb +1 -1
  34. data/lib/rom/sql/extensions/postgres/types/geometric.rb +19 -19
  35. data/lib/rom/sql/extensions/postgres/types/json.rb +12 -18
  36. data/lib/rom/sql/extensions/postgres/types/ltree.rb +54 -97
  37. data/lib/rom/sql/extensions/postgres/types/network.rb +4 -17
  38. data/lib/rom/sql/extensions/postgres/types/range.rb +30 -30
  39. data/lib/rom/sql/extensions/postgres/types.rb +14 -14
  40. data/lib/rom/sql/extensions/postgres.rb +6 -6
  41. data/lib/rom/sql/extensions/rails_log_subscriber.rb +6 -21
  42. data/lib/rom/sql/extensions/sqlite/types.rb +1 -1
  43. data/lib/rom/sql/extensions/sqlite.rb +2 -2
  44. data/lib/rom/sql/extensions.rb +6 -6
  45. data/lib/rom/sql/foreign_key.rb +3 -1
  46. data/lib/rom/sql/function.rb +19 -42
  47. data/lib/rom/sql/gateway.rb +41 -15
  48. data/lib/rom/sql/group_dsl.rb +3 -8
  49. data/lib/rom/sql/index.rb +2 -0
  50. data/lib/rom/sql/join_dsl.rb +1 -1
  51. data/lib/rom/sql/mapper_compiler.rb +2 -2
  52. data/lib/rom/sql/migration/inline_runner.rb +2 -8
  53. data/lib/rom/sql/migration/migrator.rb +12 -12
  54. data/lib/rom/sql/migration/recorder.rb +4 -10
  55. data/lib/rom/sql/migration/runner.rb +4 -5
  56. data/lib/rom/sql/migration/schema_diff.rb +4 -10
  57. data/lib/rom/sql/migration/writer.rb +7 -7
  58. data/lib/rom/sql/migration.rb +9 -13
  59. data/lib/rom/sql/order_dsl.rb +3 -7
  60. data/lib/rom/sql/plugin/associates.rb +45 -21
  61. data/lib/rom/sql/plugin/pagination.rb +3 -1
  62. data/lib/rom/sql/plugin/schema_indexes.rb +35 -0
  63. data/lib/rom/sql/plugins.rb +9 -6
  64. data/lib/rom/sql/projection_dsl.rb +5 -5
  65. data/lib/rom/sql/rake_task.rb +2 -2
  66. data/lib/rom/sql/relation/reading.rb +78 -83
  67. data/lib/rom/sql/relation/writing.rb +4 -9
  68. data/lib/rom/sql/relation.rb +58 -136
  69. data/lib/rom/sql/restriction_dsl.rb +4 -8
  70. data/lib/rom/sql/schema/attributes_inferrer.rb +2 -2
  71. data/lib/rom/sql/schema/dsl.rb +6 -4
  72. data/lib/rom/sql/schema/index_dsl.rb +6 -7
  73. data/lib/rom/sql/schema/inferrer.rb +22 -24
  74. data/lib/rom/sql/schema/type_builder.rb +4 -20
  75. data/lib/rom/sql/schema.rb +17 -29
  76. data/lib/rom/sql/spec/support.rb +5 -5
  77. data/lib/rom/sql/tasks/migration_tasks.rake +14 -21
  78. data/lib/rom/sql/transaction.rb +4 -3
  79. data/lib/rom/sql/type_dsl.rb +3 -7
  80. data/lib/rom/sql/type_extensions.rb +6 -4
  81. data/lib/rom/sql/type_serializer.rb +9 -9
  82. data/lib/rom/sql/types.rb +6 -6
  83. data/lib/rom/sql/version.rb +1 -1
  84. data/lib/rom/sql/wrap.rb +1 -1
  85. data/lib/rom/sql.rb +13 -12
  86. data/lib/rom/types/values.rb +5 -3
  87. data/lib/rom-sql.rb +1 -1
  88. metadata +17 -12
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/core/class_attributes'
3
+ require "dry/core/class_attributes"
4
4
 
5
5
  module ROM
6
6
  module SQL
@@ -12,7 +12,7 @@ module ROM
12
12
 
13
13
  defines :type_builders
14
14
 
15
- CONSTRAINT_DB_TYPE = 'add_constraint'
15
+ CONSTRAINT_DB_TYPE = "add_constraint"
16
16
 
17
17
  option :type_builder
18
18
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/sql/schema/index_dsl'
3
+ require "rom/compat/schema/dsl"
4
+ require_relative "index_dsl"
4
5
 
5
6
  module ROM
6
7
  module SQL
@@ -8,6 +9,7 @@ module ROM
8
9
  # Specialized schema DSL with SQL-specific features
9
10
  #
10
11
  # @api public
12
+ # @deprecated
11
13
  class DSL < ROM::Schema::DSL
12
14
  # @!attribute [r] index_dsl
13
15
  # @return [IndexDSL] Index DSL instance (created only if indexes block is called)
@@ -16,8 +18,8 @@ module ROM
16
18
  # Define indexes within a block
17
19
  #
18
20
  # @api public
19
- def indexes(&)
20
- @index_dsl = IndexDSL.new(**options, &)
21
+ def indexes(&block)
22
+ @index_dsl = IndexDSL.new(**options, &block)
21
23
  end
22
24
 
23
25
  private
@@ -29,7 +31,7 @@ module ROM
29
31
  if index_dsl
30
32
  opts = super
31
33
 
32
- { **opts, indexes: index_dsl.(relation, opts[:attributes]) }
34
+ {**opts, indexes: index_dsl.(relation, opts[:attributes])}
33
35
  else
34
36
  super
35
37
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
3
+ require "set"
4
4
 
5
5
  module ROM
6
6
  module SQL
@@ -14,13 +14,12 @@ module ROM
14
14
  attr_reader :registry
15
15
 
16
16
  # @api private
17
- def initialize(*, **, &)
17
+ def initialize(*, &block)
18
18
  super
19
-
20
19
  @registry = []
21
-
22
- instance_exec(&)
20
+ instance_exec(&block) if block
23
21
  end
22
+ ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
24
23
 
25
24
  # @api public
26
25
  def index(*attributes, **options)
@@ -33,9 +32,9 @@ module ROM
33
32
  attr_class.new(attr[:type], **(attr[:options] || {})).meta(source: schema_name)
34
33
  end
35
34
 
36
- registry.to_set do |attr_names, options|
35
+ registry.map { |attr_names, options|
37
36
  build_index(attributes, attr_names, options)
38
- end
37
+ }.to_set
39
38
  end
40
39
 
41
40
  private
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
3
+ require "set"
4
4
 
5
- require 'rom/sql/schema/type_builder'
6
- require 'rom/sql/schema/attributes_inferrer'
7
- require 'rom/sql/attribute'
5
+ require "rom/sql/schema/type_builder"
6
+ require "rom/sql/schema/attributes_inferrer"
7
+ require "rom/sql/attribute"
8
8
 
9
9
  module ROM
10
10
  module SQL
@@ -40,7 +40,7 @@ module ROM
40
40
  end
41
41
  rescue Sequel::Error => e
42
42
  on_error(schema.name, e)
43
- { **FALLBACK_SCHEMA, indexes: schema.indexes }
43
+ {**FALLBACK_SCHEMA, indexes: schema.indexes}
44
44
  end
45
45
 
46
46
  # @api private
@@ -49,14 +49,12 @@ module ROM
49
49
  indexes = indexes_from_database(gateway, schema, idx)
50
50
  foreign_keys = foreign_keys_from_database(gateway, schema, idx)
51
51
 
52
- {
53
- **rest,
52
+ {**rest,
54
53
  attributes: attributes.map { |attr|
55
- mark_fk(mark_indexed(attr, indexes), foreign_keys)
56
- },
54
+ mark_fk(mark_indexed(attr, indexes), foreign_keys)
55
+ },
57
56
  foreign_keys: foreign_keys,
58
- indexes: indexes
59
- }
57
+ indexes: indexes}
60
58
  end
61
59
 
62
60
  # @api private
@@ -64,12 +62,10 @@ module ROM
64
62
  indexes = schema.indexes | indexes_from_attributes(attributes)
65
63
  foreign_keys = foreign_keys_from_attributes(attributes)
66
64
 
67
- {
68
- **rest,
65
+ {**rest,
69
66
  attributes: attributes.map { |attr| mark_indexed(attr, indexes) },
70
67
  foreign_keys: foreign_keys,
71
- indexes: indexes
72
- }
68
+ indexes: indexes}
73
69
  end
74
70
 
75
71
  # @api private
@@ -77,12 +73,12 @@ module ROM
77
73
  if gateway.connection.respond_to?(:indexes)
78
74
  dataset = schema.name.dataset
79
75
 
80
- gateway.connection.indexes(dataset).to_set do |index_name, definition|
76
+ gateway.connection.indexes(dataset).map { |index_name, definition|
81
77
  columns, unique = definition.values_at(:columns, :unique)
82
78
  attrs = columns.map { |name| attributes[name] }
83
79
 
84
80
  SQL::Index.new(attrs, name: index_name, unique: unique)
85
- end
81
+ }.to_set
86
82
  else
87
83
  EMPTY_SET
88
84
  end
@@ -92,26 +88,28 @@ module ROM
92
88
  def foreign_keys_from_database(gateway, schema, attributes)
93
89
  dataset = schema.name.dataset
94
90
 
95
- gateway.connection.foreign_key_list(dataset).to_set do |definition|
91
+ gateway.connection.foreign_key_list(dataset).map { |definition|
96
92
  columns, table, key = definition.values_at(:columns, :table, :key)
97
93
  attrs = columns.map { |name| attributes[name] }
98
94
 
99
95
  SQL::ForeignKey.new(attrs, table, parent_keys: key)
100
- end
96
+ }.to_set
101
97
  end
102
98
 
103
99
  # @api private
104
100
  def indexes_from_attributes(attributes)
105
101
  attributes
106
102
  .select(&:indexed?)
107
- .to_set { |attr| SQL::Index.new([attr.unwrap]) }
103
+ .map { |attr| SQL::Index.new([attr.unwrap]) }
104
+ .to_set
108
105
  end
109
106
 
110
107
  # @api private
111
108
  def foreign_keys_from_attributes(attributes)
112
109
  attributes
113
110
  .select(&:foreign_key?)
114
- .to_set { |attr| SQL::ForeignKey.new([attr.unwrap], attr.target) }
111
+ .map { |attr| SQL::ForeignKey.new([attr.unwrap], attr.target) }
112
+ .to_set
115
113
  end
116
114
 
117
115
  # @api private
@@ -155,9 +153,9 @@ module ROM
155
153
  raise e
156
154
  elsif !silent
157
155
  warn "[#{dataset}] failed to infer schema. " \
158
- 'Make sure tables exist before ROM container is set up. ' \
159
- 'This may also happen when your migration tasks load ROM container, ' \
160
- 'which is not needed for migrations as only the connection is required ' \
156
+ "Make sure tables exist before ROM container is set up. " \
157
+ "This may also happen when your migration tasks load ROM container, " \
158
+ "which is not needed for migrations as only the connection is required " \
161
159
  "(#{e.message})"
162
160
  end
163
161
  end
@@ -21,7 +21,7 @@ module ROM
21
21
 
22
22
  defines :ruby_type_mapping, :numeric_pk_type
23
23
 
24
- DECIMAL_REGEX = /(?:decimal|numeric)\((\d+)(?:,\s*(\d+))?\)/
24
+ DECIMAL_REGEX = /(?:decimal|numeric)\((\d+)(?:,\s*(\d+))?\)/.freeze
25
25
 
26
26
  ruby_type_mapping(
27
27
  integer: Types::Integer,
@@ -37,10 +37,6 @@ module ROM
37
37
 
38
38
  numeric_pk_type Types::Serial
39
39
 
40
- TYPE_GUESSES = {
41
- /datetime\((\d+)\)/ => :datetime
42
- }.freeze
43
-
44
40
  def call(primary_key:, db_type:, type:, allow_null:, **rest)
45
41
  if primary_key
46
42
  map_pk_type(type, db_type, **rest)
@@ -67,29 +63,17 @@ module ROM
67
63
  end
68
64
 
69
65
  # @api private
70
- #
71
- # rubocop:disable Metrics/PerceivedComplexity
72
66
  def map_type(ruby_type, db_type, **kw)
73
- type = self.class.ruby_type_mapping[ruby_type || guess_type(db_type)]
67
+ type = self.class.ruby_type_mapping[ruby_type]
74
68
 
75
- if (db_type.is_a?(String) && db_type.include?('numeric')) || db_type.include?('decimal')
69
+ if (db_type.is_a?(String) && db_type.include?("numeric")) || db_type.include?("decimal")
76
70
  map_decimal_type(db_type)
77
- elsif db_type.is_a?(String) && db_type.include?('char') && kw[:max_length]
71
+ elsif db_type.is_a?(String) && db_type.include?("char") && kw[:max_length]
78
72
  type.meta(limit: kw[:max_length])
79
73
  else
80
74
  type
81
75
  end
82
76
  end
83
- # rubocop:enable Metrics/PerceivedComplexity
84
-
85
- # @api private
86
- def guess_type(db_type)
87
- TYPE_GUESSES.find do |regex, type|
88
- if db_type.is_a?(String) && db_type.match(regex)
89
- break type
90
- end
91
- end
92
- end
93
77
 
94
78
  # @api private
95
79
  def map_decimal_type(type)
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/schema'
3
+ require "rom/schema"
4
4
 
5
- require 'rom/sql/schema/dsl'
6
- require 'rom/sql/order_dsl'
7
- require 'rom/sql/group_dsl'
8
- require 'rom/sql/projection_dsl'
9
- require 'rom/sql/restriction_dsl'
10
- require 'rom/sql/index'
11
- require 'rom/sql/foreign_key'
12
- require 'rom/sql/schema/inferrer'
5
+ require "rom/sql/order_dsl"
6
+ require "rom/sql/group_dsl"
7
+ require "rom/sql/projection_dsl"
8
+ require "rom/sql/restriction_dsl"
9
+ require "rom/sql/index"
10
+ require "rom/sql/foreign_key"
11
+ require "rom/sql/schema/inferrer"
13
12
 
14
13
  module ROM
15
14
  module SQL
@@ -32,8 +31,8 @@ module ROM
32
31
  # @return [Mixed] Result of the block call
33
32
  #
34
33
  # @api public
35
- def restriction(&)
36
- RestrictionDSL.new(self).call(&)
34
+ def restriction(&block)
35
+ RestrictionDSL.new(self).call(&block)
37
36
  end
38
37
 
39
38
  # Open Order DSL for setting ORDER clause in queries
@@ -43,8 +42,8 @@ module ROM
43
42
  # @return [Mixed] Result of the block call
44
43
  #
45
44
  # @api public
46
- def order(&)
47
- OrderDSL.new(self).call(&)
45
+ def order(&block)
46
+ OrderDSL.new(self).call(&block)
48
47
  end
49
48
 
50
49
  # Open Group DSL for setting GROUP BY clause in queries
@@ -54,8 +53,8 @@ module ROM
54
53
  # @return [Mixed] Result of the block call
55
54
  #
56
55
  # @api public
57
- def group(&)
58
- GroupDSL.new(self).call(&)
56
+ def group(&block)
57
+ GroupDSL.new(self).call(&block)
59
58
  end
60
59
 
61
60
  # Return a new schema with attributes marked as qualified
@@ -87,9 +86,9 @@ module ROM
87
86
  # @return [Schema] A new schema with projected attributes
88
87
  #
89
88
  # @api public
90
- def project(*names, &)
91
- if block_given?
92
- super(*(names + ProjectionDSL.new(self).(&)))
89
+ def project(*names, &block)
90
+ if block
91
+ super(*(names + ProjectionDSL.new(self).(&block)))
93
92
  else
94
93
  super
95
94
  end
@@ -162,17 +161,6 @@ module ROM
162
161
  end
163
162
  end
164
163
 
165
- # Finalize associations
166
- #
167
- # @api private
168
- def finalize_associations!(relations:)
169
- super do
170
- associations.map do |definition|
171
- SQL::Associations.const_get(definition.type).new(definition, relations)
172
- end
173
- end
174
- end
175
-
176
164
  memoize :qualified, :canonical, :joined, :project_pk
177
165
  end
178
166
  end
@@ -7,18 +7,18 @@ else
7
7
  end
8
8
 
9
9
  if USING_JRUBY
10
- SEQUEL_TEST_DB_URI = 'jdbc:sqlite::memory:'
10
+ SEQUEL_TEST_DB_URI = "jdbc:sqlite::memory:"
11
11
  else
12
- SEQUEL_TEST_DB_URI = 'sqlite::memory'
12
+ SEQUEL_TEST_DB_URI = "sqlite::memory"
13
13
  end
14
14
 
15
15
  DB = Sequel.connect(SEQUEL_TEST_DB_URI)
16
16
 
17
17
  def seed(db = DB)
18
- db.run('CREATE TABLE users (id INTEGER PRIMARY KEY, name STRING)')
18
+ db.run("CREATE TABLE users (id INTEGER PRIMARY KEY, name STRING)")
19
19
 
20
- db[:users].insert(id: 1, name: 'Jane')
21
- db[:users].insert(id: 2, name: 'Joe')
20
+ db[:users].insert(id: 1, name: "Jane")
21
+ db[:users].insert(id: 2, name: "Joe")
22
22
  end
23
23
 
24
24
  def deseed(db = DB)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
4
- require 'fileutils'
3
+ require "pathname"
4
+ require "fileutils"
5
5
 
6
6
  module ROM
7
7
  module SQL
@@ -10,11 +10,11 @@ module ROM
10
10
 
11
11
  class << self
12
12
  def run_migrations(options = {})
13
- gateway.run_migrations(migration_options.merge(options))
13
+ gateway.run_migrations(options)
14
14
  end
15
15
 
16
- def create_migration(...)
17
- gateway.migrator.create_file(...)
16
+ def create_migration(*args)
17
+ gateway.migrator.create_file(*args)
18
18
  end
19
19
 
20
20
  # Global environment used for running migrations. You normally
@@ -24,12 +24,6 @@ module ROM
24
24
  # @api public
25
25
  attr_accessor :env
26
26
 
27
- # Migration options, which are passed to `ROM::SQL::RakeSupport.run_migrations`. You can
28
- # set them in the `db:setup` task with `ROM::SQL::RakeSupport.migration_options = { ... }`
29
- #
30
- # @api public
31
- attr_accessor :migration_options
32
-
33
27
  private
34
28
 
35
29
  def gateway
@@ -37,7 +31,7 @@ module ROM
37
31
  Gateway.instance ||
38
32
  raise(
39
33
  MissingEnv,
40
- 'Set up a configuration with ROM::SQL::RakeSupport.env= in the db:setup task'
34
+ "Set up a configuration with ROM::SQL::RakeSupport.env= in the db:setup task"
41
35
  )
42
36
  else
43
37
  env.gateways[:default]
@@ -46,43 +40,42 @@ module ROM
46
40
  end
47
41
 
48
42
  @env = nil
49
- @migration_options = {}
50
43
  end
51
44
  end
52
45
  end
53
46
 
54
47
  namespace :db do
55
48
  task :rom_configuration do
56
- Rake::Task['db:setup'].invoke
49
+ Rake::Task["db:setup"].invoke
57
50
  end
58
51
 
59
- desc 'Perform migration reset (full erase and migration up)'
52
+ desc "Perform migration reset (full erase and migration up)"
60
53
  task reset: :rom_configuration do
61
54
  ROM::SQL::RakeSupport.run_migrations(target: 0)
62
55
  ROM::SQL::RakeSupport.run_migrations
63
- puts '<= db:reset executed'
56
+ puts "<= db:reset executed"
64
57
  end
65
58
 
66
- desc 'Migrate the database (options [version_number])]'
59
+ desc "Migrate the database (options [version_number])]"
67
60
  task :migrate, [:version] => :rom_configuration do |_, args|
68
61
  version = args[:version]
69
62
 
70
63
  if version.nil?
71
64
  ROM::SQL::RakeSupport.run_migrations
72
- puts '<= db:migrate executed'
65
+ puts "<= db:migrate executed"
73
66
  else
74
67
  ROM::SQL::RakeSupport.run_migrations(target: version.to_i)
75
68
  puts "<= db:migrate version=[#{version}] executed"
76
69
  end
77
70
  end
78
71
 
79
- desc 'Perform migration down (removes all tables)'
72
+ desc "Perform migration down (removes all tables)"
80
73
  task clean: :rom_configuration do
81
74
  ROM::SQL::RakeSupport.run_migrations(target: 0)
82
- puts '<= db:clean executed'
75
+ puts "<= db:clean executed"
83
76
  end
84
77
 
85
- desc 'Create a migration (parameters: NAME, VERSION)'
78
+ desc "Create a migration (parameters: NAME, VERSION)"
86
79
  task :create_migration, %i[name version] => :rom_configuration do |_, args|
87
80
  name, version = args.values_at(:name, :version)
88
81
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rom/transaction"
4
+
3
5
  module ROM
4
6
  module SQL
5
7
  # @api private
@@ -8,12 +10,11 @@ module ROM
8
10
  private :connection
9
11
 
10
12
  def initialize(connection)
11
- super()
12
13
  @connection = connection
13
14
  end
14
15
 
15
- def run(opts = EMPTY_HASH)
16
- connection.transaction(opts) { yield(self) }
16
+ def run(**options)
17
+ connection.transaction(options) { yield(self) }
17
18
  rescue ::ROM::Transaction::Rollback
18
19
  # noop
19
20
  end
@@ -6,11 +6,7 @@ module ROM
6
6
  #
7
7
  # @api public
8
8
  class TypeDSL
9
- attr_reader :definition
10
-
11
- attr_reader :input_constructor
12
-
13
- attr_reader :output_constructor
9
+ attr_reader :definition, :input_constructor, :output_constructor
14
10
 
15
11
  # @api private
16
12
  def initialize(value_type)
@@ -22,8 +18,8 @@ module ROM
22
18
  end
23
19
 
24
20
  # @api private
25
- def call(&)
26
- instance_exec(&)
21
+ def call(&block)
22
+ instance_exec(&block)
27
23
 
28
24
  definition.constructor(input_constructor)
29
25
  .meta(read: definition.constructor(output_constructor))
@@ -30,13 +30,15 @@ module ROM
30
30
  # @param [Dry::Types::Type] type Type
31
31
  #
32
32
  # @api public
33
- def register(type, &)
33
+ def register(type, &block)
34
34
  extensions = @types[type.meta[:database]]
35
35
  db_type = type.meta[:db_type]
36
36
 
37
- mod = ::Module.new(&)
38
- ctx = ::Object.new.extend(mod)
39
- functions = mod.public_instance_methods.to_h { |m| [m, ctx.method(m)] }
37
+ mod = Module.new(&block)
38
+ ctx = Object.new.extend(mod)
39
+ functions = mod.public_instance_methods.each_with_object({}) { |m, ms|
40
+ ms[m] = ctx.method(m)
41
+ }
40
42
  extensions[db_type] = (extensions[db_type] || {}).merge(functions)
41
43
  end
42
44
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/core/class_attributes'
3
+ require "dry/core/class_attributes"
4
4
 
5
5
  module ROM
6
6
  module SQL
@@ -23,19 +23,19 @@ module ROM
23
23
  defines :mapping
24
24
 
25
25
  mapping(
26
- Types::Integer => 'integer',
27
- Types::String => 'varchar',
28
- Types::Time => 'timestamp',
29
- Types::Date => 'date',
30
- Types::Bool => 'boolean',
31
- Types::Decimal => 'numeric',
32
- Types::Float => 'float'
26
+ Types::Integer => "integer",
27
+ Types::String => "varchar",
28
+ Types::Time => "timestamp",
29
+ Types::Date => "date",
30
+ Types::Bool => "boolean",
31
+ Types::Decimal => "numeric",
32
+ Types::Float => "float"
33
33
  )
34
34
 
35
35
  def call(type)
36
36
  return type.meta[:db_type] if type.meta[:db_type]
37
37
 
38
- meta = type.meta[:read] ? { read: type.meta[:read] } : EMPTY_HASH
38
+ meta = type.meta[:read] ? {read: type.meta[:read]} : EMPTY_HASH
39
39
 
40
40
  self.class.mapping.fetch(type.with(meta: meta)) {
41
41
  if block_given?
data/lib/rom/sql/types.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'sequel/core'
4
- require 'sequel/sql'
3
+ require "sequel/core"
4
+ require "sequel/sql"
5
5
 
6
- require 'rom/types'
7
- require 'rom/sql/type_dsl'
6
+ require "rom/types"
7
+ require "rom/sql/type_dsl"
8
8
 
9
9
  module ROM
10
10
  module SQL
@@ -37,8 +37,8 @@ module ROM
37
37
  # @return [Dry::Types::Nominal]
38
38
  #
39
39
  # @api public
40
- def self.define(value_type, &)
41
- TypeDSL.new(value_type).call(&)
40
+ def self.define(value_type, &block)
41
+ TypeDSL.new(value_type).call(&block)
42
42
  end
43
43
 
44
44
  Serial = Integer.meta(primary_key: true)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ROM
4
4
  module SQL
5
- VERSION = '3.7.0'
5
+ VERSION = "4.0.0.alpha1"
6
6
  end
7
7
  end
data/lib/rom/sql/wrap.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/relation/wrap'
3
+ require "rom/relation/wrap"
4
4
 
5
5
  module ROM
6
6
  module SQL
data/lib/rom/sql.rb CHANGED
@@ -1,22 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/core'
3
+ require "rom/core"
4
4
 
5
- require 'rom/sql/version'
6
- require 'rom/sql/errors'
5
+ require "rom/sql/version"
6
+ require "rom/sql/errors"
7
7
 
8
- require 'rom/configuration_dsl'
9
-
10
- require 'rom/sql/plugins'
11
- require 'rom/sql/relation'
12
- require 'rom/sql/mapper_compiler'
13
- require 'rom/sql/associations'
14
- require 'rom/sql/gateway'
15
- require 'rom/sql/migration'
16
- require 'rom/sql/extensions'
8
+ require "rom/sql/plugins"
9
+ require "rom/sql/relation"
10
+ require "rom/sql/mapper_compiler"
11
+ require "rom/sql/associations"
12
+ require "rom/sql/gateway"
13
+ require "rom/sql/migration"
14
+ require "rom/sql/extensions"
17
15
 
18
16
  if defined?(Rails)
19
17
  ROM::SQL.load_extensions(:active_support_notifications, :rails_log_subscriber)
20
18
  end
21
19
 
22
20
  ROM.register_adapter(:sql, ROM::SQL)
21
+
22
+ # Enable :default_view for all SQL relations
23
+ ROM::SQL::Gateway.plugin(relations: :default_views)
@@ -1,13 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/sql/types'
3
+ require "rom/sql/types"
4
4
 
5
5
  module ROM
6
6
  module Types
7
7
  module Values
8
- class TreePath < ::Struct.new(:value, :separator) # rubocop:disable Style/StructInheritance
8
+ class TreePath < ::Struct.new(:value, :separator)
9
+ DEFAULT_SEPARATOR = "."
10
+
9
11
  # @api public
10
- def self.new(value, separator = '.')
12
+ def self.new(value, separator = DEFAULT_SEPARATOR)
11
13
  super
12
14
  end
13
15