event_store 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
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
- ### Creating a client
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 the events associated with an aggregate, including its snapshot
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(255) NOT NULL)
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
 
@@ -1,3 +1,3 @@
1
1
  module EventStore
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: