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 direct queries without using the LINQ api #32

Merged
merged 5 commits into from
Apr 25, 2019

Conversation

borigas
Copy link
Collaborator

@borigas borigas commented Apr 24, 2019

Provides a workaround for query edge cases that aren't supported

Copy link
Owner

@matteobortolazzo matteobortolazzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!
Also query from string.
And the README must be updated.

What is not supported at the moment?

@borigas
Copy link
Collaborator Author

borigas commented Apr 25, 2019

Query from string was my 1st goal too. I think this does support string though. Flurl will take whatever object you pass and JSON serialize it to send. If it's a string, it'll serialize to itself.

I'm not currently aware of anything not supported, but I wanted a workaround available if I found something else like the Guid .In() change from #31 so I wasn't blocked until it got merged

@matteobortolazzo
Copy link
Owner

matteobortolazzo commented Apr 25, 2019

If you serialize a string it will wrap everything in "".
For example "{"selector":{"name":"Luke"}}" and it's not a valid JSON.

No worries, I'm working on this.

       public Task<List<TSource>> QueryAsync(string mangoQueryJson)
        {
            return SendQueryAsync(r => r
                .WithHeader("Content-Type", "application/json")
                .PostStringAsync(mangoQueryJson));
        }

       
        public Task<List<TSource>> QueryAsync(object mangoQuery)
        {
            return SendQueryAsync(r => r
                .PostJsonAsync(mangoQuery));
        }

        private async Task<List<TSource>> SendQueryAsync(Func<IFlurlRequest, Task<HttpResponseMessage>> requestFunc)
        {
            var request = NewRequest()
                .AppendPathSegment("_find");

            var message = requestFunc(request);

            var findResult = await message
                .ReceiveJson<FindResult<TSource>>()
                .SendRequestAsync()
                .ConfigureAwait(false);

            return findResult.Docs.ToList();
        }

Adds QueryAsync documentation.
Adds QueryAsync to README.
@matteobortolazzo matteobortolazzo merged commit 178f0b1 into dev Apr 25, 2019
@matteobortolazzo matteobortolazzo deleted the StringQuery branch April 25, 2019 21:07
@borigas
Copy link
Collaborator Author

borigas commented Apr 25, 2019

And that's why I should've written a test for both use cases... Good catch and thanks for fixing it

@matteobortolazzo
Copy link
Owner

No worries :)
1.0.1-beta.4 out soon

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

Successfully merging this pull request may close these issues.

2 participants