rom-sql 3.6.4 → 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 (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -48
  3. data/LICENSE +1 -1
  4. data/README.md +1 -1
  5. data/lib/rom/plugins/relation/sql/auto_restrictions.rb +11 -10
  6. data/lib/rom/plugins/relation/sql/default_views.rb +75 -0
  7. data/lib/rom/plugins/relation/sql/instrumentation.rb +8 -13
  8. data/lib/rom/plugins/relation/sql/postgres/explain.rb +4 -4
  9. data/lib/rom/plugins/relation/sql/postgres/full_text_search.rb +18 -16
  10. data/lib/rom/plugins/relation/sql/postgres/streaming.rb +12 -9
  11. data/lib/rom/sql/associations/many_to_many.rb +7 -7
  12. data/lib/rom/sql/associations/many_to_one.rb +3 -3
  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 +9 -9
  19. data/lib/rom/sql/attribute_aliasing.rb +2 -3
  20. data/lib/rom/sql/commands/create.rb +5 -4
  21. data/lib/rom/sql/commands/delete.rb +2 -2
  22. data/lib/rom/sql/commands/update.rb +5 -4
  23. data/lib/rom/sql/commands.rb +4 -4
  24. data/lib/rom/sql/dsl.rb +3 -3
  25. data/lib/rom/sql/errors.rb +3 -3
  26. data/lib/rom/sql/extensions/active_support_notifications.rb +4 -4
  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 +27 -27
  35. data/lib/rom/sql/extensions/postgres/types/json.rb +9 -9
  36. data/lib/rom/sql/extensions/postgres/types/ltree.rb +61 -34
  37. data/lib/rom/sql/extensions/postgres/types/network.rb +4 -17
  38. data/lib/rom/sql/extensions/postgres/types/range.rb +25 -25
  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 +18 -22
  47. data/lib/rom/sql/gateway.rb +44 -17
  48. data/lib/rom/sql/group_dsl.rb +1 -1
  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/migrator.rb +11 -11
  53. data/lib/rom/sql/migration/runner.rb +3 -3
  54. data/lib/rom/sql/migration/schema_diff.rb +7 -8
  55. data/lib/rom/sql/migration/writer.rb +12 -12
  56. data/lib/rom/sql/migration.rb +4 -8
  57. data/lib/rom/sql/order_dsl.rb +1 -1
  58. data/lib/rom/sql/plugin/associates.rb +49 -11
  59. data/lib/rom/sql/plugin/pagination.rb +5 -3
  60. data/lib/rom/sql/plugin/schema_indexes.rb +35 -0
  61. data/lib/rom/sql/plugins.rb +9 -6
  62. data/lib/rom/sql/projection_dsl.rb +4 -4
  63. data/lib/rom/sql/rake_task.rb +2 -2
  64. data/lib/rom/sql/relation/reading.rb +34 -27
  65. data/lib/rom/sql/relation/writing.rb +11 -10
  66. data/lib/rom/sql/relation.rb +57 -89
  67. data/lib/rom/sql/restriction_dsl.rb +2 -2
  68. data/lib/rom/sql/schema/attributes_inferrer.rb +3 -3
  69. data/lib/rom/sql/schema/dsl.rb +4 -2
  70. data/lib/rom/sql/schema/index_dsl.rb +3 -5
  71. data/lib/rom/sql/schema/inferrer.rb +25 -23
  72. data/lib/rom/sql/schema/type_builder.rb +2 -2
  73. data/lib/rom/sql/schema.rb +9 -21
  74. data/lib/rom/sql/spec/support.rb +5 -5
  75. data/lib/rom/sql/tasks/migration_tasks.rake +13 -21
  76. data/lib/rom/sql/transaction.rb +4 -2
  77. data/lib/rom/sql/type_extensions.rb +3 -1
  78. data/lib/rom/sql/type_serializer.rb +10 -10
  79. data/lib/rom/sql/types.rb +4 -4
  80. data/lib/rom/sql/version.rb +1 -1
  81. data/lib/rom/sql/wrap.rb +1 -1
  82. data/lib/rom/sql.rb +13 -12
  83. data/lib/rom/types/values.rb +2 -2
  84. data/lib/rom-sql.rb +1 -1
  85. metadata +13 -17
@@ -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
@@ -141,7 +140,7 @@ module ROM
141
140
  #
142
141
  # @api public
143
142
  def call(relation)
144
- relation.new(relation.dataset.select(*self.qualified_projection), schema: self)
143
+ relation.new(relation.dataset.select(*qualified_projection), schema: self)
145
144
  end
146
145
 
147
146
  # Return an empty schema
@@ -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,7 +10,7 @@ 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
16
  def create_migration(*args)
@@ -24,13 +24,6 @@ module ROM
24
24
  # @api public
25
25
  attr_accessor :env
26
26
 
27
-
28
- # Migration options, which are passed to `ROM::SQL::RakeSupport.run_migrations`. You can
29
- # set them in the `db:setup` task with `ROM::SQL::RakeSupport.migration_options = { ... }`
30
- #
31
- # @api public
32
- attr_accessor :migration_options
33
-
34
27
  private
35
28
 
36
29
  def gateway
@@ -38,7 +31,7 @@ module ROM
38
31
  Gateway.instance ||
39
32
  raise(
40
33
  MissingEnv,
41
- '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"
42
35
  )
43
36
  else
44
37
  env.gateways[:default]
@@ -47,44 +40,43 @@ module ROM
47
40
  end
48
41
 
49
42
  @env = nil
50
- @migration_options = {}
51
43
  end
52
44
  end
53
45
  end
54
46
 
55
47
  namespace :db do
56
48
  task :rom_configuration do
57
- Rake::Task['db:setup'].invoke
49
+ Rake::Task["db:setup"].invoke
58
50
  end
59
51
 
60
- desc 'Perform migration reset (full erase and migration up)'
52
+ desc "Perform migration reset (full erase and migration up)"
61
53
  task reset: :rom_configuration do
62
54
  ROM::SQL::RakeSupport.run_migrations(target: 0)
63
55
  ROM::SQL::RakeSupport.run_migrations
64
- puts '<= db:reset executed'
56
+ puts "<= db:reset executed"
65
57
  end
66
58
 
67
- desc 'Migrate the database (options [version_number])]'
59
+ desc "Migrate the database (options [version_number])]"
68
60
  task :migrate, [:version] => :rom_configuration do |_, args|
69
61
  version = args[:version]
70
62
 
71
63
  if version.nil?
72
64
  ROM::SQL::RakeSupport.run_migrations
73
- puts '<= db:migrate executed'
65
+ puts "<= db:migrate executed"
74
66
  else
75
67
  ROM::SQL::RakeSupport.run_migrations(target: version.to_i)
76
68
  puts "<= db:migrate version=[#{version}] executed"
77
69
  end
78
70
  end
79
71
 
80
- desc 'Perform migration down (removes all tables)'
72
+ desc "Perform migration down (removes all tables)"
81
73
  task clean: :rom_configuration do
82
74
  ROM::SQL::RakeSupport.run_migrations(target: 0)
83
- puts '<= db:clean executed'
75
+ puts "<= db:clean executed"
84
76
  end
85
77
 
86
- desc 'Create a migration (parameters: NAME, VERSION)'
87
- task :create_migration, [:name, :version] => :rom_configuration do |_, args|
78
+ desc "Create a migration (parameters: NAME, VERSION)"
79
+ task :create_migration, %i[name version] => :rom_configuration do |_, args|
88
80
  name, version = args.values_at(:name, :version)
89
81
 
90
82
  if name.nil?
@@ -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
@@ -11,8 +13,8 @@ module ROM
11
13
  @connection = connection
12
14
  end
13
15
 
14
- def run(opts = EMPTY_HASH)
15
- connection.transaction(opts) { yield(self) }
16
+ def run(**options)
17
+ connection.transaction(options) { yield(self) }
16
18
  rescue ::ROM::Transaction::Rollback
17
19
  # noop
18
20
  end
@@ -36,7 +36,9 @@ module ROM
36
36
 
37
37
  mod = Module.new(&block)
38
38
  ctx = Object.new.extend(mod)
39
- functions = mod.public_instance_methods.each_with_object({}) { |m, ms| ms[m] = ctx.method(m) }
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,24 +23,24 @@ 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?
42
42
  yield(type)
43
- end or raise "Cannot serialize #{ type }"
43
+ end or raise "Cannot serialize #{type}"
44
44
  }
45
45
  end
46
46
  end
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ROM
4
4
  module SQL
5
- VERSION = "3.6.4"
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,12 +1,12 @@
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
8
  class TreePath < ::Struct.new(:value, :separator)
9
- DEFAULT_SEPARATOR = '.'.freeze
9
+ DEFAULT_SEPARATOR = "."
10
10
 
11
11
  # @api public
12
12
  def self.new(value, separator = DEFAULT_SEPARATOR)
data/lib/rom-sql.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rom/sql'
3
+ require "rom/sql"
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: 3.6.4
4
+ version: 4.0.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-01 00:00:00.000000000 Z
11
+ date: 2022-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -30,48 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: '1.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: '1.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dry-core
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
47
+ version: '0.7'
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: '1.0'
54
+ version: '0.7'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rom
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '5.2'
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 5.2.1
61
+ version: 6.0.0.alpha
65
62
  type: :runtime
66
63
  prerelease: false
67
64
  version_requirements: !ruby/object:Gem::Requirement
68
65
  requirements:
69
66
  - - "~>"
70
67
  - !ruby/object:Gem::Version
71
- version: '5.2'
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 5.2.1
68
+ version: 6.0.0.alpha
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: bundler
77
71
  requirement: !ruby/object:Gem::Requirement
@@ -126,6 +120,7 @@ files:
126
120
  - README.md
127
121
  - lib/rom-sql.rb
128
122
  - lib/rom/plugins/relation/sql/auto_restrictions.rb
123
+ - lib/rom/plugins/relation/sql/default_views.rb
129
124
  - lib/rom/plugins/relation/sql/instrumentation.rb
130
125
  - lib/rom/plugins/relation/sql/postgres/explain.rb
131
126
  - lib/rom/plugins/relation/sql/postgres/full_text_search.rb
@@ -189,6 +184,7 @@ files:
189
184
  - lib/rom/sql/plugin/associates.rb
190
185
  - lib/rom/sql/plugin/nullify.rb
191
186
  - lib/rom/sql/plugin/pagination.rb
187
+ - lib/rom/sql/plugin/schema_indexes.rb
192
188
  - lib/rom/sql/plugins.rb
193
189
  - lib/rom/sql/projection_dsl.rb
194
190
  - lib/rom/sql/rake_task.rb
@@ -231,11 +227,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
231
227
  version: 2.7.0
232
228
  required_rubygems_version: !ruby/object:Gem::Requirement
233
229
  requirements:
234
- - - ">="
230
+ - - ">"
235
231
  - !ruby/object:Gem::Version
236
- version: '0'
232
+ version: 1.3.1
237
233
  requirements: []
238
- rubygems_version: 3.5.3
234
+ rubygems_version: 3.3.7
239
235
  signing_key:
240
236
  specification_version: 4
241
237
  summary: SQL databases support for ROM