rom-sql 3.5.0 → 4.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -3
  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 +11 -10
  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 -24
  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 +2 -2
  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 +3 -3
  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 +17 -16
  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 +2 -2
  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 +1 -1
  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 +12 -12
  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 -14
  83. data/lib/rom/types/values.rb +2 -2
  84. data/lib/rom-sql.rb +1 -1
  85. metadata +14 -24
@@ -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
@@ -31,7 +31,7 @@ module ROM
31
31
  Gateway.instance ||
32
32
  raise(
33
33
  MissingEnv,
34
- '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"
35
35
  )
36
36
  else
37
37
  env.gateways[:default]
@@ -46,37 +46,37 @@ end
46
46
 
47
47
  namespace :db do
48
48
  task :rom_configuration do
49
- Rake::Task['db:setup'].invoke
49
+ Rake::Task["db:setup"].invoke
50
50
  end
51
51
 
52
- desc 'Perform migration reset (full erase and migration up)'
52
+ desc "Perform migration reset (full erase and migration up)"
53
53
  task reset: :rom_configuration do
54
54
  ROM::SQL::RakeSupport.run_migrations(target: 0)
55
55
  ROM::SQL::RakeSupport.run_migrations
56
- puts '<= db:reset executed'
56
+ puts "<= db:reset executed"
57
57
  end
58
58
 
59
- desc 'Migrate the database (options [version_number])]'
59
+ desc "Migrate the database (options [version_number])]"
60
60
  task :migrate, [:version] => :rom_configuration do |_, args|
61
61
  version = args[:version]
62
62
 
63
63
  if version.nil?
64
64
  ROM::SQL::RakeSupport.run_migrations
65
- puts '<= db:migrate executed'
65
+ puts "<= db:migrate executed"
66
66
  else
67
67
  ROM::SQL::RakeSupport.run_migrations(target: version.to_i)
68
68
  puts "<= db:migrate version=[#{version}] executed"
69
69
  end
70
70
  end
71
71
 
72
- desc 'Perform migration down (removes all tables)'
72
+ desc "Perform migration down (removes all tables)"
73
73
  task clean: :rom_configuration do
74
74
  ROM::SQL::RakeSupport.run_migrations(target: 0)
75
- puts '<= db:clean executed'
75
+ puts "<= db:clean executed"
76
76
  end
77
77
 
78
- desc 'Create a migration (parameters: NAME, VERSION)'
79
- 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|
80
80
  name, version = args.values_at(:name, :version)
81
81
 
82
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.5.0'.freeze
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,24 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/equalizer'
3
+ require "rom/core"
4
4
 
5
- require 'rom/core'
5
+ require "rom/sql/version"
6
+ require "rom/sql/errors"
6
7
 
7
- require 'rom/sql/version'
8
- require 'rom/sql/errors'
9
-
10
- require 'rom/configuration_dsl'
11
-
12
- require 'rom/sql/plugins'
13
- require 'rom/sql/relation'
14
- require 'rom/sql/mapper_compiler'
15
- require 'rom/sql/associations'
16
- require 'rom/sql/gateway'
17
- require 'rom/sql/migration'
18
- 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"
19
15
 
20
16
  if defined?(Rails)
21
17
  ROM::SQL.load_extensions(:active_support_notifications, :rails_log_subscriber)
22
18
  end
23
19
 
24
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.5.0
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: 2021-03-26 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,54 +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: '0.5'
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: '0.5'
47
+ version: '0.7'
51
48
  type: :runtime
52
49
  prerelease: false
53
50
  version_requirements: !ruby/object:Gem::Requirement
54
51
  requirements:
55
52
  - - "~>"
56
53
  - !ruby/object:Gem::Version
57
- version: '0.5'
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '0.5'
54
+ version: '0.7'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: rom
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
59
  - - "~>"
66
60
  - !ruby/object:Gem::Version
67
- version: '5.2'
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: 5.2.1
61
+ version: 6.0.0.alpha
71
62
  type: :runtime
72
63
  prerelease: false
73
64
  version_requirements: !ruby/object:Gem::Requirement
74
65
  requirements:
75
66
  - - "~>"
76
67
  - !ruby/object:Gem::Version
77
- version: '5.2'
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: 5.2.1
68
+ version: 6.0.0.alpha
81
69
  - !ruby/object:Gem::Dependency
82
70
  name: bundler
83
71
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +120,7 @@ files:
132
120
  - README.md
133
121
  - lib/rom-sql.rb
134
122
  - lib/rom/plugins/relation/sql/auto_restrictions.rb
123
+ - lib/rom/plugins/relation/sql/default_views.rb
135
124
  - lib/rom/plugins/relation/sql/instrumentation.rb
136
125
  - lib/rom/plugins/relation/sql/postgres/explain.rb
137
126
  - lib/rom/plugins/relation/sql/postgres/full_text_search.rb
@@ -195,6 +184,7 @@ files:
195
184
  - lib/rom/sql/plugin/associates.rb
196
185
  - lib/rom/sql/plugin/nullify.rb
197
186
  - lib/rom/sql/plugin/pagination.rb
187
+ - lib/rom/sql/plugin/schema_indexes.rb
198
188
  - lib/rom/sql/plugins.rb
199
189
  - lib/rom/sql/projection_dsl.rb
200
190
  - lib/rom/sql/rake_task.rb
@@ -234,14 +224,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
234
224
  requirements:
235
225
  - - ">="
236
226
  - !ruby/object:Gem::Version
237
- version: 2.4.0
227
+ version: 2.7.0
238
228
  required_rubygems_version: !ruby/object:Gem::Requirement
239
229
  requirements:
240
- - - ">="
230
+ - - ">"
241
231
  - !ruby/object:Gem::Version
242
- version: '0'
232
+ version: 1.3.1
243
233
  requirements: []
244
- rubygems_version: 3.2.3
234
+ rubygems_version: 3.3.7
245
235
  signing_key:
246
236
  specification_version: 4
247
237
  summary: SQL databases support for ROM