rom-sql 3.1.0 → 3.2.0
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/lib/rom-sql.rb +2 -0
- data/lib/rom/plugins/relation/sql/auto_restrictions.rb +2 -0
- data/lib/rom/plugins/relation/sql/instrumentation.rb +2 -0
- data/lib/rom/plugins/relation/sql/postgres/explain.rb +6 -7
- data/lib/rom/sql.rb +2 -0
- data/lib/rom/sql/associations.rb +2 -0
- data/lib/rom/sql/associations/core.rb +3 -1
- data/lib/rom/sql/associations/many_to_many.rb +2 -0
- data/lib/rom/sql/associations/many_to_one.rb +2 -0
- data/lib/rom/sql/associations/one_to_many.rb +2 -0
- data/lib/rom/sql/associations/one_to_one.rb +2 -0
- data/lib/rom/sql/associations/one_to_one_through.rb +2 -0
- data/lib/rom/sql/associations/self_ref.rb +2 -0
- data/lib/rom/sql/attribute.rb +9 -5
- data/lib/rom/sql/commands.rb +2 -0
- data/lib/rom/sql/commands/create.rb +2 -0
- data/lib/rom/sql/commands/delete.rb +2 -0
- data/lib/rom/sql/commands/error_wrapper.rb +2 -0
- data/lib/rom/sql/commands/update.rb +2 -0
- data/lib/rom/sql/dsl.rb +11 -3
- data/lib/rom/sql/error.rb +2 -0
- data/lib/rom/sql/errors.rb +2 -0
- data/lib/rom/sql/extensions.rb +2 -0
- data/lib/rom/sql/extensions/active_support_notifications.rb +2 -0
- data/lib/rom/sql/extensions/mysql.rb +2 -0
- data/lib/rom/sql/extensions/mysql/type_builder.rb +2 -0
- data/lib/rom/sql/extensions/postgres.rb +2 -0
- data/lib/rom/sql/extensions/postgres/commands.rb +2 -0
- data/lib/rom/sql/extensions/postgres/type_builder.rb +6 -4
- data/lib/rom/sql/extensions/postgres/type_serializer.rb +2 -0
- data/lib/rom/sql/extensions/postgres/types.rb +2 -0
- data/lib/rom/sql/extensions/postgres/types/array.rb +6 -4
- data/lib/rom/sql/extensions/postgres/types/array_types.rb +3 -1
- data/lib/rom/sql/extensions/postgres/types/geometric.rb +2 -0
- data/lib/rom/sql/extensions/postgres/types/json.rb +13 -11
- data/lib/rom/sql/extensions/postgres/types/ltree.rb +25 -23
- data/lib/rom/sql/extensions/postgres/types/network.rb +2 -0
- data/lib/rom/sql/extensions/postgres/types/range.rb +2 -0
- data/lib/rom/sql/extensions/rails_log_subscriber.rb +2 -0
- data/lib/rom/sql/extensions/sqlite.rb +2 -0
- data/lib/rom/sql/extensions/sqlite/type_builder.rb +2 -0
- data/lib/rom/sql/extensions/sqlite/types.rb +2 -0
- data/lib/rom/sql/foreign_key.rb +3 -1
- data/lib/rom/sql/function.rb +3 -1
- data/lib/rom/sql/gateway.rb +3 -1
- data/lib/rom/sql/group_dsl.rb +2 -0
- data/lib/rom/sql/index.rb +2 -0
- data/lib/rom/sql/join_dsl.rb +2 -0
- data/lib/rom/sql/mapper_compiler.rb +2 -0
- data/lib/rom/sql/migration.rb +5 -3
- data/lib/rom/sql/migration/inline_runner.rb +2 -0
- data/lib/rom/sql/migration/migrator.rb +4 -2
- data/lib/rom/sql/migration/recorder.rb +2 -0
- data/lib/rom/sql/migration/runner.rb +4 -2
- data/lib/rom/sql/migration/schema_diff.rb +2 -0
- data/lib/rom/sql/migration/template.rb +2 -0
- data/lib/rom/sql/migration/writer.rb +12 -4
- data/lib/rom/sql/order_dsl.rb +2 -0
- data/lib/rom/sql/plugin/associates.rb +4 -2
- data/lib/rom/sql/plugin/nullify.rb +2 -0
- data/lib/rom/sql/plugin/pagination.rb +2 -0
- data/lib/rom/sql/plugins.rb +2 -0
- data/lib/rom/sql/projection_dsl.rb +2 -0
- data/lib/rom/sql/rake_task.rb +2 -0
- data/lib/rom/sql/relation.rb +2 -0
- data/lib/rom/sql/relation/reading.rb +5 -3
- data/lib/rom/sql/relation/writing.rb +2 -0
- data/lib/rom/sql/restriction_dsl.rb +9 -1
- data/lib/rom/sql/schema.rb +3 -1
- data/lib/rom/sql/schema/attributes_inferrer.rb +5 -3
- data/lib/rom/sql/schema/dsl.rb +3 -1
- data/lib/rom/sql/schema/index_dsl.rb +5 -2
- data/lib/rom/sql/schema/inferrer.rb +12 -8
- data/lib/rom/sql/schema/type_builder.rb +4 -2
- data/lib/rom/sql/spec/support.rb +5 -3
- data/lib/rom/sql/tasks/migration_tasks.rake +16 -11
- data/lib/rom/sql/transaction.rb +2 -0
- data/lib/rom/sql/type_dsl.rb +2 -0
- data/lib/rom/sql/type_extensions.rb +2 -0
- data/lib/rom/sql/type_serializer.rb +2 -0
- data/lib/rom/sql/types.rb +2 -0
- data/lib/rom/sql/version.rb +3 -1
- data/lib/rom/sql/wrap.rb +2 -0
- data/lib/rom/types/values.rb +2 -0
- metadata +7 -7
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/sql/dsl'
|
2
4
|
|
3
5
|
module ROM
|
@@ -6,7 +8,13 @@ module ROM
|
|
6
8
|
class RestrictionDSL < DSL
|
7
9
|
# @api private
|
8
10
|
def call(&block)
|
9
|
-
|
11
|
+
arg, kwargs = select_relations(block.parameters)
|
12
|
+
|
13
|
+
if kwargs.nil?
|
14
|
+
instance_exec(arg, &block)
|
15
|
+
else
|
16
|
+
instance_exec(**kwargs, &block)
|
17
|
+
end
|
10
18
|
end
|
11
19
|
|
12
20
|
private
|
data/lib/rom/sql/schema.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/schema'
|
2
4
|
|
3
5
|
require 'rom/sql/schema/dsl'
|
@@ -142,7 +144,7 @@ module ROM
|
|
142
144
|
# Finalize all attributes by qualifying them and initializing primary key names
|
143
145
|
#
|
144
146
|
# @api private
|
145
|
-
def finalize_attributes!(options
|
147
|
+
def finalize_attributes!(**options)
|
146
148
|
super do
|
147
149
|
@attributes = map(&:qualified)
|
148
150
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry/core/class_attributes'
|
2
4
|
|
3
5
|
module ROM
|
@@ -22,8 +24,8 @@ module ROM
|
|
22
24
|
|
23
25
|
columns = filter_columns(gateway.connection.schema(dataset))
|
24
26
|
|
25
|
-
inferred = columns.map do |
|
26
|
-
type = type_builder.(definition)
|
27
|
+
inferred = columns.map do |name, definition|
|
28
|
+
type = type_builder.(**definition)
|
27
29
|
|
28
30
|
attr_class.new(type.meta(source: schema.name), name: name) if type
|
29
31
|
end.compact
|
@@ -42,7 +44,7 @@ module ROM
|
|
42
44
|
|
43
45
|
# @api private
|
44
46
|
def filter_columns(schema)
|
45
|
-
schema.reject { |
|
47
|
+
schema.reject { |_, definition| definition[:db_type] == CONSTRAINT_DB_TYPE }
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
data/lib/rom/sql/schema/dsl.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rom/sql/schema/index_dsl'
|
2
4
|
|
3
5
|
module ROM
|
@@ -15,7 +17,7 @@ module ROM
|
|
15
17
|
#
|
16
18
|
# @api public
|
17
19
|
def indexes(&block)
|
18
|
-
@index_dsl = IndexDSL.new(options, &block)
|
20
|
+
@index_dsl = IndexDSL.new(**options, &block)
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'set'
|
2
4
|
|
3
5
|
module ROM
|
@@ -19,6 +21,7 @@ module ROM
|
|
19
21
|
|
20
22
|
instance_exec(&block)
|
21
23
|
end
|
24
|
+
ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
|
22
25
|
|
23
26
|
# @api public
|
24
27
|
def index(*attributes, **options)
|
@@ -28,7 +31,7 @@ module ROM
|
|
28
31
|
# @api private
|
29
32
|
def call(schema_name, attrs)
|
30
33
|
attributes = attrs.map do |attr|
|
31
|
-
attr_class.new(attr[:type], attr[:options] || {}).meta(source: schema_name)
|
34
|
+
attr_class.new(attr[:type], **(attr[:options] || {})).meta(source: schema_name)
|
32
35
|
end
|
33
36
|
|
34
37
|
registry.map { |attr_names, options|
|
@@ -44,7 +47,7 @@ module ROM
|
|
44
47
|
attributes.find { |a| a.name == name }.unwrap
|
45
48
|
end
|
46
49
|
|
47
|
-
Index.new(index_attributes, options)
|
50
|
+
Index.new(index_attributes, **options)
|
48
51
|
end
|
49
52
|
end
|
50
53
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'set'
|
2
4
|
|
3
5
|
require 'rom/sql/schema/type_builder'
|
@@ -32,9 +34,9 @@ module ROM
|
|
32
34
|
# @api private
|
33
35
|
def call(schema, gateway)
|
34
36
|
if enabled?
|
35
|
-
infer_from_database(gateway, schema, super)
|
37
|
+
infer_from_database(gateway, schema, **super)
|
36
38
|
else
|
37
|
-
infer_from_attributes(gateway, schema, super)
|
39
|
+
infer_from_attributes(gateway, schema, **super)
|
38
40
|
end
|
39
41
|
rescue Sequel::Error => error
|
40
42
|
on_error(schema.name, error)
|
@@ -54,7 +56,7 @@ module ROM
|
|
54
56
|
end
|
55
57
|
|
56
58
|
# @api private
|
57
|
-
def infer_from_attributes(
|
59
|
+
def infer_from_attributes(_gateway, schema, attributes:, **rest)
|
58
60
|
indexes = schema.indexes | indexes_from_attributes(attributes)
|
59
61
|
foreign_keys = foreign_keys_from_attributes(attributes)
|
60
62
|
|
@@ -69,7 +71,8 @@ module ROM
|
|
69
71
|
if gateway.connection.respond_to?(:indexes)
|
70
72
|
dataset = schema.name.dataset
|
71
73
|
|
72
|
-
gateway.connection.indexes(dataset).map { |index_name,
|
74
|
+
gateway.connection.indexes(dataset).map { |index_name, definition|
|
75
|
+
columns, unique = definition.values_at(:columns, :unique)
|
73
76
|
attrs = columns.map { |name| attributes[name] }
|
74
77
|
|
75
78
|
SQL::Index.new(attrs, name: index_name, unique: unique)
|
@@ -83,7 +86,8 @@ module ROM
|
|
83
86
|
def foreign_keys_from_database(gateway, schema, attributes)
|
84
87
|
dataset = schema.name.dataset
|
85
88
|
|
86
|
-
gateway.connection.foreign_key_list(dataset).map { |
|
89
|
+
gateway.connection.foreign_key_list(dataset).map { |definition|
|
90
|
+
columns, table, key = definition.values_at(:columns, :table, :key)
|
87
91
|
attrs = columns.map { |name| attributes[name] }
|
88
92
|
|
89
93
|
SQL::ForeignKey.new(attrs, table, parent_keys: key)
|
@@ -147,9 +151,9 @@ module ROM
|
|
147
151
|
raise e
|
148
152
|
elsif !silent
|
149
153
|
warn "[#{dataset}] failed to infer schema. " \
|
150
|
-
|
151
|
-
|
152
|
-
|
154
|
+
'Make sure tables exist before ROM container is set up. ' \
|
155
|
+
'This may also happen when your migration tasks load ROM container, ' \
|
156
|
+
'which is not needed for migrations as only the connection is required ' \
|
153
157
|
"(#{e.message})"
|
154
158
|
end
|
155
159
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ROM
|
2
4
|
module SQL
|
3
5
|
class Schema
|
@@ -37,9 +39,9 @@ module ROM
|
|
37
39
|
|
38
40
|
def call(primary_key:, db_type:, type:, allow_null:, **rest)
|
39
41
|
if primary_key
|
40
|
-
map_pk_type(type, db_type, rest)
|
42
|
+
map_pk_type(type, db_type, **rest)
|
41
43
|
else
|
42
|
-
mapped_type = map_type(type, db_type, rest)
|
44
|
+
mapped_type = map_type(type, db_type, **rest)
|
43
45
|
|
44
46
|
if mapped_type
|
45
47
|
read_type = mapped_type.meta[:read]
|
data/lib/rom/sql/spec/support.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
if defined? JRUBY_VERSION
|
2
4
|
USING_JRUBY = true
|
3
5
|
else
|
@@ -5,15 +7,15 @@ else
|
|
5
7
|
end
|
6
8
|
|
7
9
|
if USING_JRUBY
|
8
|
-
SEQUEL_TEST_DB_URI =
|
10
|
+
SEQUEL_TEST_DB_URI = 'jdbc:sqlite::memory:'
|
9
11
|
else
|
10
|
-
SEQUEL_TEST_DB_URI =
|
12
|
+
SEQUEL_TEST_DB_URI = 'sqlite::memory'
|
11
13
|
end
|
12
14
|
|
13
15
|
DB = Sequel.connect(SEQUEL_TEST_DB_URI)
|
14
16
|
|
15
17
|
def seed(db = DB)
|
16
|
-
db.run(
|
18
|
+
db.run('CREATE TABLE users (id INTEGER PRIMARY KEY, name STRING)')
|
17
19
|
|
18
20
|
db[:users].insert(id: 1, name: 'Jane')
|
19
21
|
db[:users].insert(id: 2, name: 'Joe')
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'fileutils'
|
3
5
|
|
4
6
|
module ROM
|
5
7
|
module SQL
|
@@ -27,7 +29,10 @@ module ROM
|
|
27
29
|
def gateway
|
28
30
|
if env.nil?
|
29
31
|
Gateway.instance ||
|
30
|
-
raise(
|
32
|
+
raise(
|
33
|
+
MissingEnv,
|
34
|
+
'Set up a configuration with ROM::SQL::RakeSupport.env= in the db:setup task'
|
35
|
+
)
|
31
36
|
else
|
32
37
|
env.gateways[:default]
|
33
38
|
end
|
@@ -41,36 +46,36 @@ end
|
|
41
46
|
|
42
47
|
namespace :db do
|
43
48
|
task :rom_configuration do
|
44
|
-
Rake::Task[
|
49
|
+
Rake::Task['db:setup'].invoke
|
45
50
|
end
|
46
51
|
|
47
|
-
desc
|
52
|
+
desc 'Perform migration reset (full erase and migration up)'
|
48
53
|
task reset: :rom_configuration do
|
49
54
|
ROM::SQL::RakeSupport.run_migrations(target: 0)
|
50
55
|
ROM::SQL::RakeSupport.run_migrations
|
51
|
-
puts
|
56
|
+
puts '<= db:reset executed'
|
52
57
|
end
|
53
58
|
|
54
|
-
desc
|
59
|
+
desc 'Migrate the database (options [version_number])]'
|
55
60
|
task :migrate, [:version] => :rom_configuration do |_, args|
|
56
61
|
version = args[:version]
|
57
62
|
|
58
63
|
if version.nil?
|
59
64
|
ROM::SQL::RakeSupport.run_migrations
|
60
|
-
puts
|
65
|
+
puts '<= db:migrate executed'
|
61
66
|
else
|
62
67
|
ROM::SQL::RakeSupport.run_migrations(target: version.to_i)
|
63
68
|
puts "<= db:migrate version=[#{version}] executed"
|
64
69
|
end
|
65
70
|
end
|
66
71
|
|
67
|
-
desc
|
72
|
+
desc 'Perform migration down (erase all data)'
|
68
73
|
task clean: :rom_configuration do
|
69
74
|
ROM::SQL::RakeSupport.run_migrations(target: 0)
|
70
|
-
puts
|
75
|
+
puts '<= db:clean executed'
|
71
76
|
end
|
72
77
|
|
73
|
-
desc
|
78
|
+
desc 'Create a migration (parameters: NAME, VERSION)'
|
74
79
|
task :create_migration, [:name, :version] => :rom_configuration do |_, args|
|
75
80
|
name, version = args.values_at(:name, :version)
|
76
81
|
|
data/lib/rom/sql/transaction.rb
CHANGED
data/lib/rom/sql/type_dsl.rb
CHANGED
data/lib/rom/sql/types.rb
CHANGED
data/lib/rom/sql/version.rb
CHANGED
data/lib/rom/sql/wrap.rb
CHANGED
data/lib/rom/types/values.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: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -72,20 +72,20 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '5.
|
75
|
+
version: '5.2'
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version: 5.
|
78
|
+
version: 5.2.1
|
79
79
|
type: :runtime
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
83
|
- - "~>"
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: '5.
|
85
|
+
version: '5.2'
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 5.
|
88
|
+
version: 5.2.1
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: appraisal
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -261,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
261
261
|
- !ruby/object:Gem::Version
|
262
262
|
version: '0'
|
263
263
|
requirements: []
|
264
|
-
rubygems_version: 3.0.
|
264
|
+
rubygems_version: 3.0.6
|
265
265
|
signing_key:
|
266
266
|
specification_version: 4
|
267
267
|
summary: SQL databases support for ROM
|