-
Notifications
You must be signed in to change notification settings - Fork 4
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
Proper example for getMany #335
Comments
Can you share more details about you use-case? What is the structure of your ids, and what would you like to compute it from? Naive example from tests: const idResolver: IdResolver<string> = (value) => {
const number = value.match(/(\d+)/)?.[0] ?? ''
return `key${number}`
}
const value = await operation.getMany(['key1', 'key2'], idResolver) This resolver will extract first number sequence from a given string value and prefix it with
I will update our documentation, as you are right, this part is pretty confusing right now. |
Thanks for quick reply. I am a bit confused as your getMany is actually focused on retrieving/caching multiple keys, or, with db example, something like this: select('*').whereIn('id', keys.map(parseInt)). I am interested in trivial thing like cache the plain collection of records with some custom cacheKey, let's say menu list, where cacheKey is a simple string but the collection array requires me to use getMany according to DataSource interface. Or cursor pagination results, where again, I want to make cacheKey totally customized for each data set. Probably need to create different loaders for the same entity as I am limited with DataSource interface. |
Exactly, Can't you type your Loader as |
Ok, imagine trivial scenario, let's say I have news entity, and I want various news collections for frontpage (3 items for instance), latest (10), latest per region (5 regions x 10 items), and then paginated (5 pages). I will need to create bunch of loaders to have |
See above suggestion. My suggestion would be to define |
See this example:
|
Thanks, will try it. By making |
@tomcatmurr You can simply do |
@kibertoad, thanks for your assistance, everything works like a charm. Greetings from Kharkiv) |
glad to hear that! and appreciate you reaching out, I'll update documentation to explain these more advanced use-cases with greater details. Слава Україні! |
Hi guys, could you provide a proper example for getMany (with idResolver etc). Missing it here and in node-service-template (which is great btw). Aiming to implement it with mikro-orm.
I want to manage stuff like getAll or pagination, i.e. collections or complex objects while I am limited with Promise in get and Promise<LoadedValue[]> in getMany using DataSource interface for a loader.
The dumb way just to use get with keys like 'ALL' (for getAll) but yet in coflicts with interface.
The text was updated successfully, but these errors were encountered: