rom-sql 2.2.1 → 2.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/lib/rom/sql.rb +1 -0
- data/lib/rom/sql/dsl.rb +2 -1
- data/lib/rom/sql/extensions/postgres/commands.rb +17 -12
- data/lib/rom/sql/gateway.rb +2 -0
- data/lib/rom/sql/mapper_compiler.rb +17 -0
- data/lib/rom/sql/plugins.rb +0 -3
- data/lib/rom/sql/relation/reading.rb +2 -2
- data/lib/rom/sql/relation/writing.rb +1 -1
- data/lib/rom/sql/version.rb +1 -1
- metadata +5 -12
- data/lib/rom/sql/plugin/timestamps.rb +0 -131
- data/lib/rom/sql/schema/associations_dsl.rb +0 -188
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1b126e654068572dfe518a3f20c6b9765e81034
|
4
|
+
data.tar.gz: 24ca2db041cb3fa88c09a158108bac16eda8b59b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9a57e3e5cda1c2935d983270e366535f934740ee0a0f20ed849c9be8bb4915c143324449726271e5d7b495a1db79f41ee4a389fbe73dceeb3ff5b02bfc0237f
|
7
|
+
data.tar.gz: '0873247af106241abb709249a3a2bd4fcb8d11708cfbdeb6610cebd2d5175c1d279c136e920db767cc3ecf80882ba8972c252d64c75e9b713393b547edbb47ac'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
## v2.3.0 2017-11-17
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* Command's `:timestamp` plugin now supports passing options (GustavoCaso)
|
6
|
+
* Configuration supports hash with connection options (Kjarrigan + solnic)
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
|
10
|
+
* Aliased attributes are handled correctly in PG's commands (cflipse)
|
11
|
+
* Command extensions are properly applied in multi-adapter setups (solnic)
|
12
|
+
|
13
|
+
### Internal
|
14
|
+
|
15
|
+
* Custom SQL-specific mapper compiler was added, which is used starting from rom-core 4.1.0 (solnic)
|
16
|
+
* Command's `:timestamp` plugin was removed, as it was moved to rom-core (GustavoCaso)
|
17
|
+
|
18
|
+
[Compare v2.2.1...v2.3.0](https://github.com/rom-rb/rom-sql/compare/v2.2.1...v2.3.0)
|
19
|
+
|
1
20
|
## v2.2.1 2017-11-10
|
2
21
|
|
3
22
|
### Fixed
|
data/lib/rom/sql.rb
CHANGED
data/lib/rom/sql/dsl.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rom/support/inflector'
|
1
2
|
require 'rom/constants'
|
2
3
|
|
3
4
|
module ROM
|
@@ -49,7 +50,7 @@ module ROM
|
|
49
50
|
|
50
51
|
# @api private
|
51
52
|
def type(identifier)
|
52
|
-
type_name =
|
53
|
+
type_name = Inflector.classify(identifier)
|
53
54
|
types.const_get(type_name) if types.const_defined?(type_name)
|
54
55
|
end
|
55
56
|
|
@@ -15,7 +15,7 @@ module ROM
|
|
15
15
|
#
|
16
16
|
# @api private
|
17
17
|
def returning_dataset
|
18
|
-
relation.dataset.returning(*relation.
|
18
|
+
relation.dataset.returning(*relation.qualified_columns)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -133,18 +133,23 @@ module ROM
|
|
133
133
|
|
134
134
|
Gateway.subscribe('configuration.commands.class.before_build') do |event|
|
135
135
|
klass = event[:command]
|
136
|
-
dataset = event[:dataset]
|
137
|
-
type = dataset.db.database_type
|
138
|
-
|
139
|
-
if type == :postgres
|
140
|
-
ext =
|
141
|
-
if klass < Commands::Create
|
142
|
-
Postgres::Commands::Create
|
143
|
-
elsif klass < Commands::Update
|
144
|
-
Postgres::Commands::Update
|
145
|
-
end
|
146
136
|
|
147
|
-
|
137
|
+
# TODO: remove this conditional in favor of `adapter: :sql` in subscribe
|
138
|
+
# this is here for backward compatibilty with rom-core 4.x
|
139
|
+
if klass.adapter == :sql
|
140
|
+
dataset = event[:dataset]
|
141
|
+
type = dataset.db.database_type
|
142
|
+
|
143
|
+
if type == :postgres
|
144
|
+
ext =
|
145
|
+
if klass < Commands::Create
|
146
|
+
Postgres::Commands::Create
|
147
|
+
elsif klass < Commands::Update
|
148
|
+
Postgres::Commands::Update
|
149
|
+
end
|
150
|
+
|
151
|
+
klass.include(ext) if ext
|
152
|
+
end
|
148
153
|
end
|
149
154
|
end
|
150
155
|
end
|
data/lib/rom/sql/gateway.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rom/mapper_compiler'
|
2
|
+
|
3
|
+
module ROM
|
4
|
+
module SQL
|
5
|
+
class MapperCompiler < ROM::MapperCompiler
|
6
|
+
def visit_attribute(node)
|
7
|
+
name, _, meta = node
|
8
|
+
|
9
|
+
if meta[:wrapped]
|
10
|
+
[name, from: meta[:alias]]
|
11
|
+
else
|
12
|
+
[name]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/rom/sql/plugins.rb
CHANGED
@@ -3,13 +3,10 @@ require 'rom/plugins/relation/sql/auto_restrictions'
|
|
3
3
|
|
4
4
|
require 'rom/sql/plugin/associates'
|
5
5
|
require 'rom/sql/plugin/pagination'
|
6
|
-
require 'rom/sql/plugin/timestamps'
|
7
6
|
|
8
7
|
ROM.plugins do
|
9
8
|
adapter :sql do
|
10
9
|
register :pagination, ROM::SQL::Plugin::Pagination, type: :relation
|
11
10
|
register :associates, ROM::SQL::Plugin::Associates, type: :command
|
12
|
-
|
13
|
-
register :timestamps, ROM::SQL::Plugin::Timestamps, type: :command
|
14
11
|
end
|
15
12
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'rom/support/inflector'
|
2
2
|
|
3
3
|
module ROM
|
4
4
|
module SQL
|
@@ -90,7 +90,7 @@ module ROM
|
|
90
90
|
# @return [Relation]
|
91
91
|
#
|
92
92
|
# @api public
|
93
|
-
def prefix(name =
|
93
|
+
def prefix(name = Inflector.singularize(schema.name.dataset))
|
94
94
|
schema.prefix(name).(self)
|
95
95
|
end
|
96
96
|
|
@@ -9,7 +9,7 @@ module ROM
|
|
9
9
|
#
|
10
10
|
# @example
|
11
11
|
# users.upsert({ name: 'Jane', email: 'jane@foo.com' },
|
12
|
-
# { target: :email, update: { name: :excluded__name } }
|
12
|
+
# { target: :email, update: { name: :excluded__name } })
|
13
13
|
#
|
14
14
|
# @return [Integer] Number of affected rows
|
15
15
|
#
|
data/lib/rom/sql/version.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: 2.
|
4
|
+
version: 2.3.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: 2017-11-
|
11
|
+
date: 2017-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -78,20 +78,14 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '4.
|
82
|
-
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: 4.0.2
|
81
|
+
version: '4.1'
|
85
82
|
type: :runtime
|
86
83
|
prerelease: false
|
87
84
|
version_requirements: !ruby/object:Gem::Requirement
|
88
85
|
requirements:
|
89
86
|
- - "~>"
|
90
87
|
- !ruby/object:Gem::Version
|
91
|
-
version: '4.
|
92
|
-
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: 4.0.2
|
88
|
+
version: '4.1'
|
95
89
|
- !ruby/object:Gem::Dependency
|
96
90
|
name: bundler
|
97
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,6 +184,7 @@ files:
|
|
190
184
|
- lib/rom/sql/gateway.rb
|
191
185
|
- lib/rom/sql/group_dsl.rb
|
192
186
|
- lib/rom/sql/index.rb
|
187
|
+
- lib/rom/sql/mapper_compiler.rb
|
193
188
|
- lib/rom/sql/migration.rb
|
194
189
|
- lib/rom/sql/migration/inline_runner.rb
|
195
190
|
- lib/rom/sql/migration/migrator.rb
|
@@ -201,7 +196,6 @@ files:
|
|
201
196
|
- lib/rom/sql/order_dsl.rb
|
202
197
|
- lib/rom/sql/plugin/associates.rb
|
203
198
|
- lib/rom/sql/plugin/pagination.rb
|
204
|
-
- lib/rom/sql/plugin/timestamps.rb
|
205
199
|
- lib/rom/sql/plugins.rb
|
206
200
|
- lib/rom/sql/projection_dsl.rb
|
207
201
|
- lib/rom/sql/rake_task.rb
|
@@ -210,7 +204,6 @@ files:
|
|
210
204
|
- lib/rom/sql/relation/writing.rb
|
211
205
|
- lib/rom/sql/restriction_dsl.rb
|
212
206
|
- lib/rom/sql/schema.rb
|
213
|
-
- lib/rom/sql/schema/associations_dsl.rb
|
214
207
|
- lib/rom/sql/schema/attributes_inferrer.rb
|
215
208
|
- lib/rom/sql/schema/dsl.rb
|
216
209
|
- lib/rom/sql/schema/index_dsl.rb
|
@@ -1,131 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
module ROM
|
4
|
-
module SQL
|
5
|
-
module Plugin
|
6
|
-
# Make a command that automatically fills in timestamp attributes on
|
7
|
-
# input tuples
|
8
|
-
#
|
9
|
-
# @api private
|
10
|
-
module Timestamps
|
11
|
-
# @api private
|
12
|
-
def self.included(klass)
|
13
|
-
klass.extend(ClassInterface)
|
14
|
-
super
|
15
|
-
end
|
16
|
-
|
17
|
-
module ClassInterface
|
18
|
-
# @api private
|
19
|
-
def self.extended(klass)
|
20
|
-
klass.defines :timestamp_columns, :datestamp_columns
|
21
|
-
klass.timestamp_columns Set.new
|
22
|
-
klass.datestamp_columns Set.new
|
23
|
-
|
24
|
-
super
|
25
|
-
end
|
26
|
-
|
27
|
-
# Set up attributes to timestamp when the command is called
|
28
|
-
#
|
29
|
-
# @example
|
30
|
-
# class CreateTask < ROM::Commands::Create[:sql]
|
31
|
-
# result :one
|
32
|
-
# use :timestamps
|
33
|
-
# timestamps :created_at, :updated_at
|
34
|
-
# end
|
35
|
-
#
|
36
|
-
# create_user = rom.command(:user).create.curry(name: 'Jane')
|
37
|
-
#
|
38
|
-
# result = create_user.call
|
39
|
-
# result[:created_at] #=> Time.now.utc
|
40
|
-
#
|
41
|
-
# @param [Array<Symbol>] names A list of attribute names
|
42
|
-
#
|
43
|
-
# @api public
|
44
|
-
def timestamps(*names)
|
45
|
-
timestamp_columns timestamp_columns.merge(names)
|
46
|
-
|
47
|
-
include InstanceMethods
|
48
|
-
end
|
49
|
-
alias timestamp timestamps
|
50
|
-
|
51
|
-
# Set up attributes to datestamp when the command is called
|
52
|
-
#
|
53
|
-
# @example
|
54
|
-
# class CreateTask < ROM::Commands::Create[:sql]
|
55
|
-
# result :one
|
56
|
-
# use :timestamps
|
57
|
-
# datestamps :created_on, :updated_on
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# create_user = rom.command(:user).create.curry(name: 'Jane')
|
61
|
-
#
|
62
|
-
# result = create_user.call
|
63
|
-
# result[:created_at] #=> Date.today
|
64
|
-
#
|
65
|
-
# @param [Array<Symbol>] names A list of attribute names
|
66
|
-
#
|
67
|
-
# @api public
|
68
|
-
def datestamps(*names)
|
69
|
-
datestamp_columns datestamp_columns.merge(names)
|
70
|
-
|
71
|
-
include InstanceMethods
|
72
|
-
end
|
73
|
-
alias datestamp datestamps
|
74
|
-
end
|
75
|
-
|
76
|
-
module InstanceMethods
|
77
|
-
# @api private
|
78
|
-
def self.included(base)
|
79
|
-
base.before :set_timestamps
|
80
|
-
end
|
81
|
-
|
82
|
-
# @api private
|
83
|
-
def timestamp_columns
|
84
|
-
self.class.timestamp_columns
|
85
|
-
end
|
86
|
-
|
87
|
-
# @api private
|
88
|
-
def datestamp_columns
|
89
|
-
self.class.datestamp_columns
|
90
|
-
end
|
91
|
-
|
92
|
-
# Set the timestamp attributes on the given tuples
|
93
|
-
#
|
94
|
-
# @param [Array<Hash>, Hash] tuples the input tuple(s)
|
95
|
-
#
|
96
|
-
# @return [Array<Hash>, Hash]
|
97
|
-
#
|
98
|
-
# @api private
|
99
|
-
def set_timestamps(tuples, *)
|
100
|
-
timestamps = build_timestamps
|
101
|
-
|
102
|
-
case tuples
|
103
|
-
when Hash
|
104
|
-
timestamps.merge(tuples)
|
105
|
-
when Array
|
106
|
-
tuples.map { |t| timestamps.merge(t) }
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
private
|
111
|
-
|
112
|
-
# @api private
|
113
|
-
def build_timestamps
|
114
|
-
time = Time.now.utc
|
115
|
-
date = Date.today
|
116
|
-
timestamps = {}
|
117
|
-
timestamp_columns.each do |column|
|
118
|
-
timestamps[column.to_sym] = time
|
119
|
-
end
|
120
|
-
|
121
|
-
datestamp_columns.each do |column|
|
122
|
-
timestamps[column.to_sym] = date
|
123
|
-
end
|
124
|
-
|
125
|
-
timestamps
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
@@ -1,188 +0,0 @@
|
|
1
|
-
require 'dry/core/inflector'
|
2
|
-
|
3
|
-
require 'rom/associations/definitions'
|
4
|
-
|
5
|
-
module ROM
|
6
|
-
module SQL
|
7
|
-
class Schema < ROM::Schema
|
8
|
-
# Additional schema DSL for definition SQL associations
|
9
|
-
#
|
10
|
-
# This DSL is exposed in `associations do .. end` blocks in schema defintions.
|
11
|
-
#
|
12
|
-
# @api public
|
13
|
-
class AssociationsDSL < BasicObject
|
14
|
-
# @!attribute [r] source
|
15
|
-
# @return [Relation::Name] The source relation
|
16
|
-
attr_reader :source
|
17
|
-
|
18
|
-
# @!attribute [r] registry
|
19
|
-
# @return [RelationRegistry] Relations registry from a rom container
|
20
|
-
attr_reader :registry
|
21
|
-
|
22
|
-
# @api private
|
23
|
-
def initialize(source, &block)
|
24
|
-
@source = source
|
25
|
-
@registry = {}
|
26
|
-
instance_exec(&block)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Establish a one-to-many association
|
30
|
-
#
|
31
|
-
# @example using relation identifier
|
32
|
-
# has_many :tasks
|
33
|
-
#
|
34
|
-
# @example with a :through option
|
35
|
-
# # this establishes many-to-many association
|
36
|
-
# has_many :tasks, through: :users_tasks
|
37
|
-
#
|
38
|
-
# @example using aliased association with a custom view
|
39
|
-
# has_many :posts, as: :published_posts, view: :published
|
40
|
-
#
|
41
|
-
# @example using custom target relation
|
42
|
-
# has_many :user_posts, relation: :posts
|
43
|
-
#
|
44
|
-
# @param [Symbol] target The target relation identifier
|
45
|
-
# @param [Hash] options A hash with additional options
|
46
|
-
#
|
47
|
-
# @return [Associations::OneToMany]
|
48
|
-
#
|
49
|
-
# @see #many_to_many
|
50
|
-
#
|
51
|
-
# @api public
|
52
|
-
def one_to_many(target, options = {})
|
53
|
-
if options[:through]
|
54
|
-
many_to_many(target, options)
|
55
|
-
else
|
56
|
-
add(::ROM::Associations::Definitions::OneToMany.new(source, target, options))
|
57
|
-
end
|
58
|
-
end
|
59
|
-
alias_method :has_many, :one_to_many
|
60
|
-
|
61
|
-
# Establish a one-to-one association
|
62
|
-
#
|
63
|
-
# @example using relation identifier
|
64
|
-
# one_to_one :addresses, as: :address
|
65
|
-
#
|
66
|
-
# @example with an intermediate join relation
|
67
|
-
# one_to_one :tasks, as: :priority_task, through: :assignments
|
68
|
-
#
|
69
|
-
# @param [Symbol] target The target relation identifier
|
70
|
-
# @param [Hash] options A hash with additional options
|
71
|
-
#
|
72
|
-
# @return [Associations::OneToOne]
|
73
|
-
#
|
74
|
-
# @see #belongs_to
|
75
|
-
#
|
76
|
-
# @api public
|
77
|
-
def one_to_one(target, options = {})
|
78
|
-
if options[:through]
|
79
|
-
one_to_one_through(target, options)
|
80
|
-
else
|
81
|
-
add(::ROM::Associations::Definitions::OneToOne.new(source, target, options))
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Establish a one-to-one association with a :through option
|
86
|
-
#
|
87
|
-
# @example
|
88
|
-
# one_to_one_through :users, as: :author, through: :users_posts
|
89
|
-
#
|
90
|
-
# @return [Associations::OneToOneThrough]
|
91
|
-
#
|
92
|
-
# @api public
|
93
|
-
def one_to_one_through(target, options = {})
|
94
|
-
add(::ROM::Associations::Definitions::OneToOneThrough.new(source, target, options))
|
95
|
-
end
|
96
|
-
|
97
|
-
# Establish a many-to-many association
|
98
|
-
#
|
99
|
-
# @example using relation identifier
|
100
|
-
# many_to_many :tasks, through: :users_tasks
|
101
|
-
#
|
102
|
-
# @param [Symbol] target The target relation identifier
|
103
|
-
# @param [Hash] options A hash with additional options
|
104
|
-
#
|
105
|
-
# @return [Associations::OneToOne]
|
106
|
-
#
|
107
|
-
# @see #one_to_many
|
108
|
-
#
|
109
|
-
# @api public
|
110
|
-
def many_to_many(target, options = {})
|
111
|
-
add(::ROM::Associations::Definitions::ManyToMany.new(source, target, options))
|
112
|
-
end
|
113
|
-
|
114
|
-
# Establish a many-to-one association
|
115
|
-
#
|
116
|
-
# @example using relation identifier
|
117
|
-
# many_to_one :users, as: :author
|
118
|
-
#
|
119
|
-
# @param [Symbol] target The target relation identifier
|
120
|
-
# @param [Hash] options A hash with additional options
|
121
|
-
#
|
122
|
-
# @return [Associations::OneToOne]
|
123
|
-
#
|
124
|
-
# @see #one_to_many
|
125
|
-
#
|
126
|
-
# @api public
|
127
|
-
def many_to_one(target, options = {})
|
128
|
-
add(::ROM::Associations::Definitions::ManyToOne.new(source, target, options))
|
129
|
-
end
|
130
|
-
|
131
|
-
# Shortcut for many_to_one which sets alias automatically
|
132
|
-
#
|
133
|
-
# @example with an alias (relation identifier is inferred via pluralization)
|
134
|
-
# belongs_to :user
|
135
|
-
#
|
136
|
-
# @example with an explicit alias
|
137
|
-
# belongs_to :users, as: :author
|
138
|
-
#
|
139
|
-
# @see #many_to_one
|
140
|
-
#
|
141
|
-
# @return [Associations::ManyToOne]
|
142
|
-
#
|
143
|
-
# @api public
|
144
|
-
def belongs_to(name, options = {})
|
145
|
-
many_to_one(dataset_name(name), {as: name}.merge(options))
|
146
|
-
end
|
147
|
-
|
148
|
-
# Shortcut for one_to_one which sets alias automatically
|
149
|
-
#
|
150
|
-
# @example with an alias (relation identifier is inferred via pluralization)
|
151
|
-
# one_to_one :address
|
152
|
-
#
|
153
|
-
# @example with an explicit alias and a custom view
|
154
|
-
# one_to_one :posts, as: :priority_post, view: :prioritized
|
155
|
-
#
|
156
|
-
# @see #one_to_one
|
157
|
-
#
|
158
|
-
# @return [Associations::ManyToOne]
|
159
|
-
#
|
160
|
-
# @api public
|
161
|
-
def has_one(name, options = {})
|
162
|
-
one_to_one(dataset_name(name), {as: name}.merge(options))
|
163
|
-
end
|
164
|
-
|
165
|
-
# Return an association set for a schema
|
166
|
-
#
|
167
|
-
# @return [AssociationSet]
|
168
|
-
#
|
169
|
-
# @api private
|
170
|
-
def call
|
171
|
-
AssociationSet.new(registry)
|
172
|
-
end
|
173
|
-
|
174
|
-
private
|
175
|
-
|
176
|
-
# @api private
|
177
|
-
def add(association)
|
178
|
-
registry[association.name] = association
|
179
|
-
end
|
180
|
-
|
181
|
-
# @api private
|
182
|
-
def dataset_name(name)
|
183
|
-
::Dry::Core::Inflector.pluralize(name).to_sym
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|