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

Allow TableNameResolver to be asynchronous #289

Open
nolde opened this issue Apr 2, 2020 · 2 comments
Open

Allow TableNameResolver to be asynchronous #289

nolde opened this issue Apr 2, 2020 · 2 comments

Comments

@nolde
Copy link

nolde commented Apr 2, 2020

I have separate systems that create and manage hard resources like dynamodb tables, and that use those resources. Normally, I export those variables using different methods, but I wanted to start making my system more robust in the event of changes, including hot switching of tables. To to that, I would have to be able to resolve the name of the table in runtime.

To achieve that, I am exporting SSM parameters with the required names, but I cannot resolve it in runtime, as TableNameResolver does not support an asynchronous function to be set. As aws-sdk is mostly asynchrounous, it makes it quite hard to determine names by accessing external resources. It is achievable, but depends on complex synchronisation code that becomes an overkill.

Therefore, it would be nice if TableNameResolver could support Promise<string> as return value as well, allowing a large range of resolutions to happen.

@simonmumenthaler
Copy link
Contributor

simonmumenthaler commented Apr 23, 2020

Hi @nolde

To support an async TableNameResolver function a lot of refactoring would be necessary.

But: since the TableNameResolver is called every time a new Request instance is created (eg. myStore.get(..) --> new GetRequest()) you could simply await your own promise where you call updateDynamoEasyConfig(..) in the end with your new TableNameResolver function. Afterwards all requests would use the new function.

Only the DynamoStore actually stores the table name generated from TableNameResolver . But this property (myStore.tableName) is never used from dynamo-easy itself (We could simply replace it with a getter calling the TableNameResolver every time to be more consistent).

@nolde
Copy link
Author

nolde commented Apr 24, 2020

Yeah, your method works, but would force to do the resolution of all table names, for all models, at once.

My goal would be something like what you mention in your last paragraph; resolving it every you need to use it. That would give the developer full freedom to decide whether to cache to value, to resolve every time, and to only resolve what is absolutely needed, no extra calls involved.

I understand the changes my be slightly large, but I thought it could be a good idea, so I am throwing it out there! =)

Thanks for taking some time to consider it, and feel free to close it if it is too much.

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

No branches or pull requests

2 participants