event_store 0.1.4 → 0.1.5
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.
- data/README.md +42 -2
- data/db/migrations/001_create_event_store_events.rb +1 -1
- data/lib/event_store/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -39,8 +39,31 @@ EventStore.custom_config(redis_config, database_config)
|
|
39
39
|
4. the inet address for en0 is what you want
|
40
40
|
Hint: if it just hangs, you have have the wrong IP
|
41
41
|
|
42
|
-
|
42
|
+
|
43
|
+
### Caveat Emptor
|
44
|
+
`redis`, by default, is using database 15. Running the tests will DROP this database every time they run.
|
45
|
+
|
46
|
+
### Data Structures
|
47
|
+
EventStore uses two simple data structures:
|
48
|
+
```ruby
|
49
|
+
EventStore::Event = Struct.new(:aggregate_id, :occurred_at, :fully_qualified_name, :serialized_event, :version)
|
50
|
+
EventStore::SerializedEvent = Struct.new(:fully_qualified_name, :serialized_event, :version, :occurred_at)
|
51
|
+
```
|
52
|
+
- `aggregate_id` is a string uniquely identifying your aggregate
|
53
|
+
- `occurred_at` is a UTC timestamp (for simplicty, EventStore assumes all times given in UTC)
|
54
|
+
- `fully_qualified_name` is the connonical name of the event whose data you are storing
|
55
|
+
- `serialized_event` is a byte array representing the actual event data (in Vertica is a `VARBINARY(1000)` in postgres it is a `BYTEA`
|
56
|
+
- `version` is the monotonically increasing version number of each event. This number should be incremented by one, starting at the client's current version (see `client.version` below) for each event the client wants to store.
|
43
57
|
|
58
|
+
```ruby
|
59
|
+
client = EventStore::Client.new(device.mac_address)
|
60
|
+
EventStore::Event.new(client.id, Time.now.utc, 'name_updated', DeviceNameUpdated.to_binary, client.version + 1)
|
61
|
+
```
|
62
|
+
|
63
|
+
|
64
|
+
`EventStore::Events` are appended to the `EventStore` and `EventStore::SerializedEvent` are returned from it. The reason for the asymmetry is performance. When you are deserializing thousands or millions of events and they all have the same aggregate id, there is no reason to deserialize that field, and doubly so if you are using a column-store database like Vertica.
|
65
|
+
|
66
|
+
###Usage
|
44
67
|
```ruby
|
45
68
|
client = EventStore::Client.new(aggregate_id)
|
46
69
|
|
@@ -65,6 +88,23 @@ client.peek
|
|
65
88
|
# Get the current version of an aggregate
|
66
89
|
client.version
|
67
90
|
|
68
|
-
# Drop all
|
91
|
+
# Drop all events associated with an aggregate, including its snapshot
|
69
92
|
client.destroy!
|
93
|
+
|
94
|
+
# Drop all events associated with ALL aggregate
|
95
|
+
EventStore.clear!
|
96
|
+
```
|
97
|
+
|
98
|
+
### Rspec
|
99
|
+
To have event_store cleanup after each spec, drop this in your spec_helper.rb:
|
100
|
+
```ruby
|
101
|
+
require 'event_store'
|
102
|
+
|
103
|
+
EventStore.postgres #connect to postgres for specs, if you like
|
104
|
+
|
105
|
+
RSpec.configure do |config|
|
106
|
+
config.after(:each) do
|
107
|
+
EventStore.clear!
|
108
|
+
end
|
109
|
+
end
|
70
110
|
```
|
@@ -8,7 +8,7 @@ Sequel.migration do
|
|
8
8
|
aggregate_id varchar(36) NOT NULL,
|
9
9
|
fully_qualified_name varchar(255) NOT NULL,
|
10
10
|
occurred_at TIMESTAMPTZ NOT NULL,
|
11
|
-
serialized_event VARBINARY(
|
11
|
+
serialized_event VARBINARY(1000) NOT NULL)
|
12
12
|
|
13
13
|
PARTITION BY EXTRACT(year FROM occurred_at AT TIME ZONE 'UTC')*100 + EXTRACT(month FROM occurred_at AT TIME ZONE 'UTC');
|
14
14
|
|
data/lib/event_store/version.rb
CHANGED