FriendsOfOuro / geteventstore-php-core

PHP Client for Event Store HTTP API

Home Page:http://friendsofouro.github.io/geteventstore-php-core/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reading streams by category

fabiocarneiro opened this issue · comments

Is there a way to read the by category projection?

I'm new to getEventStore, and I have no interest of using their projection system. Instead, I would like to navigate through all the events for multiple streams myself. I made some testing projections like this one:

fromCategory('blog')
.when({
    'PostWasCreated': function(state, event) {
        state[event.data.postId] = {
            title: event.data.title,
            date: event.data.date,
            body: event.data.body
        }
    }
})

This allows me to project a collection of all the posts I have. Any idea on how I can replicate the same projection with this library?

well in this case EventStore generates a projection for you, let me check for the stream URL syntax

I suppose it is not supported. It is a different address. As far as I understood, internally Event Store gets all events from multiple streams and project them to this "by category" projection. Then from this projection you project again.

How did you do yourself when you started this library? Single stream with all events?

Try enabling the $by_category projection, and then reading from a stream name which is your category prefixed by $ce-.

So for category test, read from stream $ce-test.

Note that to enable the $by_category projection you should run GetEvenStore with the --run-projections=all option and manually enable the projection in the web interface at http://127.0.0.1:2113/web/index.html#/projections

To make sure your projection is running you can use a simple curl request:

curl -i -H 'Accept:application/vnd.eventstore.atom+json' 'http://127.0.0.1:2113/streams/$ce-test'

(Make sure to use single quotes in the curl request, otherwise it might treat $ce as variable.)

Guys I realised that I'm too busy to manage this project... anybody wants to become a project admin?