Cosmonaut icon indicating copy to clipboard operation
Cosmonaut copied to clipboard

WIP. Adds query interception, resolves #60

Open da1rren opened this issue 6 years ago • 5 comments

This pull request allows the developer to specify typed predicate which will then be applied to allow LINQ -> SQL query requests.

An example of how to configure a global filter:

var cosmosStoreSettings = new CosmosStoreSettings(_databaseId, _emulatorUri, _emulatorKey,
    settings =>
    {
        settings.AddInterceptor<Cat>(x => x.Name == "Nick");
    });

I've added integration tests covering most of the basic scenarios.

todo

  • [ ] Add docs
  • [x] Pull in QueryInterceptor.Core
  • [ ] Resolve feedback
  • [ ] Fix tests
  • [x] Fix history

da1rren avatar Feb 20 '19 10:02 da1rren

Looks like my history rewrite went a little wrong, just fixing it now.

da1rren avatar Feb 20 '19 11:02 da1rren

I think, moving it to the CosmosStore constructor as it's own thing would be more appropriate. The reason is that there are two ways to initialise the CosmosStore.

  1. Using the CosmosStoreSettings
  2. Passing your own ICosmonautClient

If you do add it in the settings then you are limiting the feature to a specific initialisation method. I's rather have it in both.

Wouldn't it be better if we have a separate class that both constructors take where you store things like query interceptors, or operations before and after like a middle-ware? See https://github.com/Elfocrash/Cosmonaut/issues/58 for example. Mats needs an Action that's invoked before the operation happens. Interceptors and request delegates could sit together on a new class.

It would also allows us to control the TEntity and validate it in compile time.

What do you think about this idea?

EDIT: Also this whole feature is more of a Query Filter than a Query Interceptor. I know it's using query interception behind the scenes but the CosmosStore Query Filter is what will end up being exposed to the user.

Elfocrash avatar Feb 20 '19 11:02 Elfocrash

@Elfocrash I agree it makes far more sense for it to exist on the CosmosStore constructor. I'll add some overrides to the constructors. It also saves a filter operation and resolves the issue with the IReadOnly collection.

da1rren avatar Feb 20 '19 13:02 da1rren

@Elfocrash The integration tests appear to be failing on Az Devops. I cannot replicate locally and the error looks suspiciously similar to some issues with the emulator I've been having recently. Would you be able to investigate?

da1rren avatar Feb 20 '19 13:02 da1rren

Don't worry about integration tests. the Cosmos DB team has been doing some stuff with the emulator and it's failing on some agents. I will deal with that problem once the feature is done.

Elfocrash avatar Feb 21 '19 09:02 Elfocrash