Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/envato/event_sourcery-postgres
Postgres event store implementation for EventSourcery
https://github.com/envato/event_sourcery-postgres
cqrs domain-driven-design event-sourcery event-sourcing postgres
Last synced: 2 months ago
JSON representation
Postgres event store implementation for EventSourcery
- Host: GitHub
- URL: https://github.com/envato/event_sourcery-postgres
- Owner: envato
- License: mit
- Created: 2017-05-15T23:39:40.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-02-22T00:25:06.000Z (11 months ago)
- Last Synced: 2024-10-31T13:57:47.555Z (3 months ago)
- Topics: cqrs, domain-driven-design, event-sourcery, event-sourcing, postgres
- Language: Ruby
- Size: 258 KB
- Stars: 13
- Watchers: 74
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# EventSourcery::Postgres
[![Build Status](https://github.com/envato/event_sourcery-postgres/workflows/tests/badge.svg?branch=main)](https://github.com/envato/event_sourcery-postgres/actions?query=workflow%3Atests+branch%3Amain)
## Development Status
EventSourcery is currently being used in production by multiple apps but we
haven't finalized the API yet and things are still moving rapidly. Until we
release a 1.0 things may change without first being deprecated.## Installation
Add this line to your application's Gemfile:
```ruby
gem 'event_sourcery-postgres'
```## Configure
```ruby
EventSourcery::Postgres.configure do |config|
config.event_store_database = Sequel.connect(...)
config.projections_database = Sequel.connect(...)
config.write_events_function_name = 'writeEvents'
config.events_table_name = :events
config.aggregates_table_name = :aggregates
config.callback_interval_if_no_new_events = 60
end
```## Usage
### Event Store
```ruby
ItemAdded = EventSourcery::EventEventSourcery::Postgres.event_store.sink(ItemAdded.new(aggregate_id: uuid, body: { }}))
EventSourcery::Postgres.event_store.get_next_from(0).each do |event|
puts event.inspect
end
```### Projectors & Reactors
```ruby
class ItemProjector
include EventSourcery::Postgres::Projectortable :items do
column :item_uuid, 'UUID NOT NULL'
column :title, 'VARCHAR(255) NOT NULL'
endproject ItemAdded do |event|
table(:items).insert(item_uuid: event.aggregate_id,
title: event.body.fetch('title'))
end
endclass UserEmailer
include EventSourcery::Postgres::Reactoremits_events SignUpEmailSent
process UserSignedUp do |event|
emit_event SignUpEmailSent.new(user_id: event.aggregate_id) do
UserMailer.signed_up(...).deliver
end
end
endEventSourcery::EventProcessing::ESPRunner.new(
event_processors: [item_projector, user_emailer],
event_store: EventSourcery::Postgres.config.event_store,
stop_on_failure: true,
).start!
```## Development
After checking out the repo, run `bin/setup` to install dependencies. (This will install dependencies and recreate the test database.) Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`.
To release a new version:
1. Update the version number in `lib/event_sourcery/postgres/version.rb`
2. Get this change onto main via the normal PR process
3. Run `bundle exec rake release`, this will create a git tag for the
version, push tags up to GitHub, and upload the gem to rubygems.org.## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/envato/event_sourcery-postgres.