Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setup example for ruby_event_store-rom #1628

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions contrib/ruby_event_store-rom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,47 @@ A Ruby Object Model (ROM) implementation of events repository for [Ruby Event St
This version of the ROM adapter supports [rom-sql](https://github.com/rom-rb/rom-sql) at this time. It is an alternative to the ActiveRecord `EventRepository` implementation used in `rails_event_store` gem.

[Read the docs to get started.](http://railseventstore.org/docs/repository/)

## Setup

### Rake tasks

Add to your `Rakefile`

```ruby
require "ruby_event_store/rom/rake_task"
```

### Database migration

A migration template can be found in [db/migrate/20210806000000_create_ruby_event_store_tables.rb](db/migrate/20210806000000_create_ruby_event_store_tables.rb).

You can choose the type of the `data` and `metadata` columns by using the `DATA_TYPE` environment variable:

```shell
rake db:migrate DATA_TYPE='text' # or
rake db:migrate DATA_TYPE='json' # or
rake db:migrate DATA_TYPE='jsonb'
```

### Application

```ruby
# config/initializers/ruby_event_store.rb

config = ROM::Configuration.new(:sql, ENV.fetch("DATABASE_URL"))
RES_ROM_CONTAINER = RubyEventStore::ROM.setup(config)

repository = RubyEventStore::ROM::EventRepository.new(
rom: RES_ROM_CONTAINER,
serializer: JSON # this setting is optional. Recommended when `data` and `metadata` are json(b) columns.
)

event_store = RubyEventStore::Client.new(repository: repository)

event_store.subscribe_to_all_events(RubyEventStore::LinkByCausationId.new(event_store: event_store))
event_store.subscribe_to_all_events(RubyEventStore::LinkByCorrelationId.new(event_store: event_store))
event_store.subscribe_to_all_events(RubyEventStore::LinkByEventType.new(event_store: event_store))

EVENT_STORE = event_store
```