rom-sql 1.0.2 → 1.0.3
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 +13 -1
- data/lib/rom/plugins/relation/sql/auto_combine.rb +19 -13
- data/lib/rom/sql/plugin/timestamps.rb +1 -1
- data/lib/rom/sql/version.rb +1 -1
- data/spec/shared/notes.rb +1 -1
- data/spec/unit/plugin/timestamp_spec.rb +36 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb7aa3ae6fc950b9149086e31c3162e99a524b37
|
4
|
+
data.tar.gz: c324b47d45d23e01fc606d65f853b163e2699a59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 172e07e4a8073164d7b9f8eec06eaefa16b052f7439a2b4d3f211cd2f932da9976df4d3a9863d525083b5e37a5dd230151b9a126f923cf8b5acdfb12b2b36469
|
7
|
+
data.tar.gz: 69352c745545be3e04a9eba2a196e0e2a3b59cd1d5f4782fa0ec9e78d78b4a5893b8bfa98f80a6bf208914ecc93a11dcc3f7e0f9549a10d764862eb110a2cf69
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,20 @@
|
|
1
|
+
## v1.0.3 2017-02-23
|
2
|
+
|
3
|
+
### Changed
|
4
|
+
|
5
|
+
* `AutoCombine#preload` uses better restriction for `ManyToOne` association which greatly speeds up loading bigger amounts of data (solnic + flash-gordon)
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
* Fix the usage of timestamp in command chains (cflipse)
|
10
|
+
|
11
|
+
[Compare v1.0.2...v1.0.3](https://github.com/rom-rb/rom-sql/compare/v1.0.2...v1.0.3)
|
12
|
+
|
1
13
|
## v1.0.2 2017-02-16
|
2
14
|
|
3
15
|
### Added
|
4
16
|
|
5
|
-
* Support for selecting literal strings via
|
17
|
+
* Support for selecting literal strings via ``select { `'foo'`.as(:bar) }`` (solnic)
|
6
18
|
|
7
19
|
[Compare v1.0.1...v1.0.2](https://github.com/rom-rb/rom-sql/compare/v1.0.1...v1.0.2)
|
8
20
|
|
@@ -33,23 +33,29 @@ module ROM
|
|
33
33
|
#
|
34
34
|
# @api private
|
35
35
|
def for_combine(spec)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
target.preload(source_key, target_key)
|
36
|
+
case spec
|
37
|
+
when ROM::SQL::Association
|
38
|
+
spec.call(__registry__, self).preload(spec)
|
39
|
+
else
|
40
|
+
preload(spec)
|
41
|
+
end
|
45
42
|
end
|
46
43
|
|
47
44
|
# @api private
|
48
|
-
def preload(
|
49
|
-
|
50
|
-
|
45
|
+
def preload(spec, source)
|
46
|
+
case spec
|
47
|
+
when ROM::SQL::Association::ManyToOne
|
48
|
+
pk = source.source[source.source.primary_key].qualified
|
49
|
+
|
50
|
+
where(pk => source.pluck(pk.name))
|
51
|
+
when Hash, ROM::SQL::Association
|
52
|
+
source_key, target_key = spec.is_a?(Hash) ? spec.flatten(1) : spec.join_keys(__registry__).flatten(1)
|
53
|
+
|
54
|
+
target_pks = source.pluck(source_key.to_sym)
|
55
|
+
target_pks.uniq!
|
51
56
|
|
52
|
-
|
57
|
+
where(target_key => target_pks)
|
58
|
+
end
|
53
59
|
end
|
54
60
|
end
|
55
61
|
end
|
data/lib/rom/sql/version.rb
CHANGED
data/spec/shared/notes.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
RSpec.shared_context 'notes' do
|
2
|
-
include_context 'database setup'
|
3
2
|
|
4
3
|
before do
|
5
4
|
inferrable_relations.concat %i(notes)
|
@@ -10,6 +9,7 @@ RSpec.shared_context 'notes' do
|
|
10
9
|
|
11
10
|
conn.create_table :notes do
|
12
11
|
primary_key :id
|
12
|
+
foreign_key :user_id, :users
|
13
13
|
String :text, null: false
|
14
14
|
# TODO: Remove Oracle's workarounds once inferer can infer not-null timestamps
|
15
15
|
DateTime :created_at, null: ctx.oracle?(example)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rom/sql/plugin/timestamps'
|
2
2
|
|
3
3
|
RSpec.describe 'Plugin / Timestamp' do
|
4
|
+
include_context 'users'
|
4
5
|
include_context 'notes'
|
5
6
|
|
6
7
|
with_adapters do
|
@@ -23,6 +24,23 @@ RSpec.describe 'Plugin / Timestamp' do
|
|
23
24
|
use :timestamps
|
24
25
|
timestamp :updated_at
|
25
26
|
end
|
27
|
+
|
28
|
+
define :create_with_user, type: :create do
|
29
|
+
result :one
|
30
|
+
use :timestamps
|
31
|
+
timestamp :updated_at, :created_at
|
32
|
+
|
33
|
+
before :assign_user
|
34
|
+
def assign_user(tuple, user)
|
35
|
+
tuple.merge(user_id: user[:id])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
conf.commands(:users) do
|
41
|
+
define :create do
|
42
|
+
result :one
|
43
|
+
end
|
26
44
|
end
|
27
45
|
end
|
28
46
|
|
@@ -77,5 +95,23 @@ RSpec.describe 'Plugin / Timestamp' do
|
|
77
95
|
expect(updated[:updated_at].iso8601).to eql(tomorrow.iso8601)
|
78
96
|
end
|
79
97
|
end
|
98
|
+
|
99
|
+
it "works with chained commands" do
|
100
|
+
create_user = container.command(:users).create.with(name: "John Doe")
|
101
|
+
create_note = container.command(:notes).create_with_user.with(text: "new note")
|
102
|
+
|
103
|
+
time = DateTime.now
|
104
|
+
command = create_user >> create_note
|
105
|
+
|
106
|
+
result = command.call
|
107
|
+
|
108
|
+
created = DateTime.parse(result[:created_at].to_s)
|
109
|
+
updated = DateTime.parse(result[:updated_at].to_s)
|
110
|
+
|
111
|
+
expect(result[:user_id]).not_to be_nil
|
112
|
+
expect(created).to be_within(1).of(time)
|
113
|
+
expect(updated).to eq created
|
114
|
+
end
|
115
|
+
|
80
116
|
end
|
81
117
|
end
|
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: 1.0.
|
4
|
+
version: 1.0.3
|
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-02-
|
11
|
+
date: 2017-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|