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

Query Async #40

Open
Jaben opened this issue Apr 26, 2019 · 4 comments
Open

Query Async #40

Jaben opened this issue Apr 26, 2019 · 4 comments

Comments

@Jaben
Copy link

Jaben commented Apr 26, 2019

First of all, thanks for this library.

Quick question: is there support for async querying?

@ttu
Copy link
Owner

ttu commented Apr 26, 2019

Hi,

There is no async support for querying. AsQueryable and Find-methods may be slow as those convert collection of JObjects to correct classes, but after conversion is done all objects are in the memory so querying is fast.

Data is in Lazy-object:
https://github.com/ttu/json-flatfile-datastore/blob/master/JsonFlatFileDataStore/DataStore.cs#L325

AsQueryable and Find-methods use data in Lazy-obejct:
https://github.com/ttu/json-flatfile-datastore/blob/master/JsonFlatFileDataStore/DocumentCollection.cs#L32

We can implement async versions for Find-methods and for AsQueryable if you think those would be useful?

@Jaben
Copy link
Author

Jaben commented Apr 29, 2019

For concurrency it would be preferable -- that lock could be async which would help with thread resources. But I don't personally need it for my usage at this time.

Was just curious if I missing something :)

Again, thanks for this useful library!

@ttu
Copy link
Owner

ttu commented May 3, 2019

Thanks for the feedback!

Have to think how async query-operations would be best to implement. Will write more specifications here when I come up with something.

@ttu ttu removed the question label May 3, 2019
@ttu
Copy link
Owner

ttu commented Jun 24, 2019

Maybe this should be implemented with async streams? Syntax might be a little nicer than with Task<IEnumerable>.

Internally both would function in a same way, as first whole JObject would be converted to correct classes. So in the end this is only about syntax.

IDocumentCollection.cs:

Task<IEnumerable<T>> AsQueryableAsync();
Task<IEnumerable<T>> FindAsync(Predicate<T> query);
var itemDynamic = (await store.GetCollection("user")
                            .AsQueryableAsync())
                            .Single(p => p.name == "Phil");

var itemDynamic2 = (await store.GetCollection("user")
		             .FindAsync(p => p.name == "Phil"))
                             .First();
					 
foreach(var item in await store.GetCollection("user").AsQueryableAsync())
{
  // TODO
}

This seems much better option

IDocumentCollection.cs:

IAsyncEnumerable<T> AsQueryableAsync();
IAsyncEnumerable<T> FindAsync(Predicate<T> query);
var itemDynamic = await store.GetCollection("user")
                            .AsQueryableAsync()
                            .Single(p => p.name == "Phil");

await foreach(var item in store.GetCollection("user").AsQueryableAsync())
{
  // TODO
}

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

No branches or pull requests

2 participants