sandthorn_driver_sequel 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sandthorn_driver_sequel/event_store.rb +32 -13
- data/lib/sandthorn_driver_sequel/version.rb +1 -1
- data/spec/driver_interface_spec.rb +3 -1
- data/spec/event_store_spec.rb +76 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72f9a33b570adeb73134ac1100b6743a319b70c7
|
4
|
+
data.tar.gz: 9b295cec40e3cc74df60e20de5b819e8cd18f33b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 665a94b687ca622f52298ba93589aeab5dd9fb4518602da78386a69762d4bf274ab50238f3551c6efb21be41e29025ea8b78b922f9844bb1ed43b310ac9043d7
|
7
|
+
data.tar.gz: ffe4491f2419a06d5a9ebbcf2469c556386c8284d9eb0446b22db06b545894542629e3c1a09f79a936bd84e568cbca0c738f9afc117eba50a34e11ccb8b328c5
|
@@ -22,6 +22,7 @@ module SandthornDriverSequel
|
|
22
22
|
new(SequelDriver.new(url: url), configuration, context)
|
23
23
|
end
|
24
24
|
|
25
|
+
#save methods
|
25
26
|
def save_events events, aggregate_id, class_name
|
26
27
|
driver.execute_in_transaction do |db|
|
27
28
|
aggregates = get_aggregate_access(db)
|
@@ -31,13 +32,6 @@ module SandthornDriverSequel
|
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
|
-
def get_aggregate_events(aggregate_id)
|
35
|
-
driver.execute do |db|
|
36
|
-
events = get_event_access(db)
|
37
|
-
events.find_events_by_aggregate_id(aggregate_id)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
35
|
def save_snapshot aggregate
|
42
36
|
driver.execute_in_transaction do |db|
|
43
37
|
snapshot_access = get_snapshot_access(db)
|
@@ -45,6 +39,25 @@ module SandthornDriverSequel
|
|
45
39
|
end
|
46
40
|
end
|
47
41
|
|
42
|
+
#get methods
|
43
|
+
def all aggregate_type
|
44
|
+
return get_aggregate_ids(aggregate_type: aggregate_type).map do |id|
|
45
|
+
get_aggregate_events_from_snapshot(id)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def find aggregate_id
|
50
|
+
get_aggregate_events_from_snapshot(aggregate_id)
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def get_aggregate_events(aggregate_id)
|
55
|
+
driver.execute do |db|
|
56
|
+
events = get_event_access(db)
|
57
|
+
events.find_events_by_aggregate_id(aggregate_id)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
48
61
|
# If the aggregate has a snapshot, return events starting from the snapshots.
|
49
62
|
# Otherwise, return all events.
|
50
63
|
# TODO: needs a better name
|
@@ -63,17 +76,17 @@ module SandthornDriverSequel
|
|
63
76
|
end
|
64
77
|
end
|
65
78
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
}
|
70
|
-
end
|
79
|
+
|
80
|
+
|
81
|
+
|
71
82
|
|
72
83
|
def get_aggregate aggregate_id, *class_name
|
73
84
|
warn(":get_aggregate is deprecated. Use :get_aggregate_events_from_snapshot")
|
74
85
|
get_aggregate_events_from_snapshot(aggregate_id)
|
75
86
|
end
|
76
87
|
|
88
|
+
|
89
|
+
|
77
90
|
def get_aggregate_ids(aggregate_type: nil)
|
78
91
|
driver.execute do |db|
|
79
92
|
access = get_aggregate_access(db)
|
@@ -83,7 +96,7 @@ module SandthornDriverSequel
|
|
83
96
|
|
84
97
|
def get_aggregate_list_by_typename(type)
|
85
98
|
warn(":get_aggregate_list_by_typenames is deprecated. Use :get_aggregate_ids")
|
86
|
-
get_aggregate_ids(
|
99
|
+
get_aggregate_ids(aggregate_type: type)
|
87
100
|
end
|
88
101
|
|
89
102
|
def get_all_types
|
@@ -121,6 +134,12 @@ module SandthornDriverSequel
|
|
121
134
|
|
122
135
|
private
|
123
136
|
|
137
|
+
def build_snapshot_event(snapshot)
|
138
|
+
{
|
139
|
+
aggregate: snapshot.data,
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
124
143
|
def transform_snapshot(snapshot)
|
125
144
|
{
|
126
145
|
aggregate_version: snapshot.aggregate_version,
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
module SandthornDriverSequel
|
3
|
+
describe EventStore do
|
4
|
+
|
5
|
+
before(:each) { prepare_for_test context: nil; }
|
6
|
+
let(:event_store) { SandthornDriverSequel.driver_from_url url: event_store_url }
|
7
|
+
|
8
|
+
describe("when getting the same data from find and get_aggregate_events_from_snapshot") do
|
9
|
+
let(:test_events) do
|
10
|
+
e = []
|
11
|
+
e << {aggregate_version: 1, event_name: "new", event_args: {:method_name=>"new", :method_args=>[], :attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>aggregate_id}]}}
|
12
|
+
e << {aggregate_version: 2, event_name: "foo", event_args: "noop"}
|
13
|
+
e << {aggregate_version: 3, event_name: "flubber", event_args: "noop"}
|
14
|
+
end
|
15
|
+
let(:aggregate_id) {"c0456e26-e29a-4f67-92fa-130b3a31a39b"}
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
before do
|
20
|
+
event_store.save_events test_events, aggregate_id, String
|
21
|
+
end
|
22
|
+
|
23
|
+
context "find" do
|
24
|
+
|
25
|
+
let(:find_events) do
|
26
|
+
event_store.find aggregate_id
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:get_aggregate_events_from_snapshot_events) do
|
30
|
+
event_store.get_aggregate_events_from_snapshot aggregate_id
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get same events" do
|
34
|
+
find_events.each_with_index do |event, index|
|
35
|
+
expect(find_events[index]).to eql get_aggregate_events_from_snapshot_events[index]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "all" do
|
41
|
+
|
42
|
+
let(:test_events_2) do
|
43
|
+
e = []
|
44
|
+
e << {aggregate_version: 1, event_name: "new", event_args: {:method_name=>"new", :method_args=>[], :attribute_deltas=>[{:attribute_name=>"aggregate_id", :old_value=>nil, :new_value=>aggregate_id_2}]}}
|
45
|
+
e << {aggregate_version: 2, event_name: "foo", event_args: "noop"}
|
46
|
+
e << {aggregate_version: 3, event_name: "flubber", event_args: "noop"}
|
47
|
+
end
|
48
|
+
let(:aggregate_id_2) {"d0456e26-e29a-4f67-92fa-130b3a31a39b"}
|
49
|
+
|
50
|
+
before do
|
51
|
+
event_store.save_events test_events_2, aggregate_id_2, String
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:all_events) do
|
55
|
+
event_store.all String
|
56
|
+
end
|
57
|
+
|
58
|
+
let(:obsolete_all) do
|
59
|
+
return event_store.get_aggregate_ids(aggregate_type: String).map do |id|
|
60
|
+
event_store.get_aggregate_events_from_snapshot(id)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should get two arrays of events" do
|
65
|
+
expect(all_events.length).to eql 2
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should get same events" do
|
69
|
+
all_events.each_with_index do |events, index|
|
70
|
+
expect(events).to eql obsolete_all[index]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sandthorn_driver_sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Krantz
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-02-
|
13
|
+
date: 2016-02-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -240,6 +240,7 @@ files:
|
|
240
240
|
- spec/db/.keep
|
241
241
|
- spec/driver_interface_spec.rb
|
242
242
|
- spec/event_access_spec.rb
|
243
|
+
- spec/event_store_spec.rb
|
243
244
|
- spec/event_store_with_context_spec.rb
|
244
245
|
- spec/get_events_spec.rb
|
245
246
|
- spec/migration_specifying_domain_spec.rb
|
@@ -280,6 +281,7 @@ test_files:
|
|
280
281
|
- spec/db/.keep
|
281
282
|
- spec/driver_interface_spec.rb
|
282
283
|
- spec/event_access_spec.rb
|
284
|
+
- spec/event_store_spec.rb
|
283
285
|
- spec/event_store_with_context_spec.rb
|
284
286
|
- spec/get_events_spec.rb
|
285
287
|
- spec/migration_specifying_domain_spec.rb
|