question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use async config

See original GitHub issue

Issue type:

[x] question [ ] bug report [x] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [x] postgres [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[x] latest [x] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

It seems that currently it is impossible to have ormconfig.js (required by cli tools to operate) to return credentials asynchronously. In case when actual credentials are not in env, but rather need to be fetched from network (e.g. from Vault, AWS SSM, etc.), it is currently impossible to have await/async in ormconfig.js and return value for cli tools to operate.

It seems that even simple await require( 'ormconfig' ) kind of code would solve the problem (and fall back to current behaior in case of sync config.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
valimerocommented, Oct 26, 2018

What’s new there ?

Same problem with MYSQL !

0reactions
leonardfactorycommented, Apr 24, 2020

I’m using ts-node, but it should be doable with plain js. I’ll take a guess:

async function getConnectionOptions() {
  const config = await configLoader.load(); // Do whatever you need in order to load asynchronously the configuration
  return config;
}

module.exports = getConnectionOptions(); // So we are returning a Promise here

You can also do this with plain promises:

function loadConfig() {
  return configLoader.load().then(config => {
    return {
       ...
    }
  });
}
module.exports = loadConfig();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't use @Async in spring boot - Stack Overflow
Put the @EnableAsync either on the class that has the @SpringBootApplciation or on a class that is annotated with @Configuration .
Read more >
Task asynchronous programming model - Microsoft Learn
Learn when and how to use Task-based async programming, a simplified approach to asynchronous programming in C#.
Read more >
require-await - ESLint - Pluggable JavaScript Linter
The primary reason to use asynchronous functions is typically to use the await operator, such as this: async function fetchData(processDataItem) { const ...
Read more >
Unable to run NUnit test from Unit Tests pad with async SetUp ...
According to NUnit documentation, it is possible to write async SetUp or TearDown method for a test: “You may specify an async method...
Read more >
An Async Example - Jest
Otherwise a fulfilled promise would not fail the test: // Testing for async errors using Promise.catch. it('tests error with promises', ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found