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

Support for queries on standard projections #4

Open
basz opened this issue Dec 23, 2017 · 2 comments
Open

Support for queries on standard projections #4

basz opened this issue Dec 23, 2017 · 2 comments

Comments

@basz
Copy link
Member

basz commented Dec 23, 2017

From @basz on March 16, 2017 15:37

on chat

I'm thinking bout updating the middleware component to add support for queries on standard projections. Would that be useful?

sounds good

It is possible to query standard projections. One QueryStandardProjection query could do it, but we would loose out on permissions etc.. so... quick and dirty

trait StandardQueryTrait {
 public function streamName(): string {
    return $this->metadata()['stream_name'];
 }

 public function result($state) {
   return $state;
  }
}
abstract class QueryStandardProjection extends Messaging\Query implements Messaging\PayloadConstructable  {
   use Messaging\StandardQueryTrait;
}

class StandardQueryHandler {
    private $projectionManager;

    public function __construct(ProjectionManager $projectionManager)
    {
        $this-> projectionManager = $projectionManager;
    }

    public function onEvent(QueryStandardProjection $query, Deferred $deferred)
    {
        // use projectionManager to retrieve state of $query->streamName()

      $deferred->resolve($query->makeResult($state));
    }
}

class MyQuery extends QueryStandardProjection {
   public function result($state) {
     return ValueObject::fromArray($state);
  }
}

routes

        [
            'name'            => 'query::something',
            'path'            => '/path',
            'middleware'      => [
                StandardQueryMiddleware::class,
            ],
            'allowed_methods' => ['OPTION', 'GET'],
            'options'         => [
                'values' => [
                    StandardQueryMiddleware::NAME_ATTRIBUTE => MyQuery::class,
                    StandardQueryMiddleware::STREAM_NAME => 'my_projection',
                ],
            ],
        ],

Which add a StandardQueryMiddleware.

It's just an rough idea... Looking for input

Copied from original issue: prooph/psr7-middleware#22

@basz
Copy link
Member Author

basz commented Dec 23, 2017

@prolic @sandrokeil @codeliner thoughts?

I now understand Query's as used in the standard projections are not traditional queries but rather projections without persisted state.... So that might skew this a little... Thought I needed to point that out...

@basz
Copy link
Member Author

basz commented Dec 23, 2017

From @prolic on March 29, 2017 3:55

I don't think it makes sense to have this as middleware. An event store query can use some time, it's more for answering some questions that arise from the business, where someone wants to know some stats f.e. and he is happy, when you give him the result the next few days. There is no need to have this exposed through the Api I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant