Elfocrash / Cosmonaut

🌐 A supercharged Azure CosmosDB .NET SDK with ORM support
https://cosmonaut.readthedocs.io
MIT License
341 stars 44 forks source link

get CosmosStore from string collection name #59

Closed StickNitro closed 5 years ago

StickNitro commented 5 years ago

I am looking to create a REST API with generic methods for CRUD across many collections and would like to know if it is possible to create a CosmosStore instance using a collection name string, or alternatively what would be the best way to accomplish this?

StickNitro commented 5 years ago

So to elaborate a bit more, let's say I have a REST API GET like this /api/v1/channel/{collectionName} or /api/v1/channel/{collectionName}/{documentId}

So I would like to be able to get all entities from {collectionName} or an entity by id, but without knowing what the Entity is until runtime

I understand the concept of shared collection and that may help me in this scenario but I cannot see any way to create a CosmosStore<T> without knowing what T is

Elfocrash commented 5 years ago

Hello @StickNitro.

CosmosStores are collection specific either occupying a full collection or part of it. Out of the box it doesn't sound like CosmosStore would be the way to go on this one. You could however, just use the CosmonautClient that has access to all the collections.

StickNitro commented 5 years ago

Would you have an example just using the CosmonautClient?

Elfocrash commented 5 years ago

The CosmonautClient is a wrapper around the DocumentClient, so really, you would use the collection name to query for entities like this: https://github.com/Elfocrash/Cosmonaut/blob/develop/samples/Cosmonaut.Console/Program.cs#L140