rom-sql 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3faf5e4b8e2aa655c4a646421cf148cad3e137e
4
- data.tar.gz: 2b1ac9258b8f15111297a71acf92f46f0f19607c
3
+ metadata.gz: fb7aa3ae6fc950b9149086e31c3162e99a524b37
4
+ data.tar.gz: c324b47d45d23e01fc606d65f853b163e2699a59
5
5
  SHA512:
6
- metadata.gz: d11f6ab0d5a70192f29b1028d5d3acd81ce8b06f3d0edb6a74c24f8c869006837630476fcda3260aa021adbd3f0b5aa321e70df50feeb6d480b701524ff34329
7
- data.tar.gz: b3f894dc4a8eddc3cca586186beaa530a0bf6317593622fca1ab86a568083dbeb88564bcba1c4110ee8230fb04c39792df0a760993908feaa999bed601e708a3
6
+ metadata.gz: 172e07e4a8073164d7b9f8eec06eaefa16b052f7439a2b4d3f211cd2f932da9976df4d3a9863d525083b5e37a5dd230151b9a126f923cf8b5acdfb12b2b36469
7
+ data.tar.gz: 69352c745545be3e04a9eba2a196e0e2a3b59cd1d5f4782fa0ec9e78d78b4a5893b8bfa98f80a6bf208914ecc93a11dcc3f7e0f9549a10d764862eb110a2cf69
@@ -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 `select { `'foo'`.as(:bar) }` (solnic)
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
- source_key, target_key, target =
37
- case spec
38
- when ROM::SQL::Association
39
- [*spec.join_keys(__registry__).flatten, spec.call(__registry__, self)]
40
- else
41
- [*spec.flatten, self]
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(source_key, target_key, source)
49
- target_pks = source.pluck(source_key.to_sym).uniq
50
- target_pks.uniq!
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
- where(target_key => target_pks)
57
+ where(target_key => target_pks)
58
+ end
53
59
  end
54
60
  end
55
61
  end
@@ -96,7 +96,7 @@ module ROM
96
96
  # @return [Array<Hash>, Hash]
97
97
  #
98
98
  # @api private
99
- def set_timestamps(tuples)
99
+ def set_timestamps(tuples, *)
100
100
  timestamps = build_timestamps
101
101
 
102
102
  case tuples
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  module SQL
3
- VERSION = '1.0.2'.freeze
3
+ VERSION = '1.0.3'.freeze
4
4
  end
5
5
  end
@@ -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.2
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-15 00:00:00.000000000 Z
11
+ date: 2017-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel