Skip to content

Commit

Permalink
feat: asynchronous ormconfig support (#5048)
Browse files Browse the repository at this point in the history
This allows a Promise to be returned from a js or ts ormconfig file.

Closes: #4149
  • Loading branch information
StevenGBrown authored and pleerock committed Nov 22, 2019
1 parent f0fd192 commit f9fdaee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/connection/ConnectionOptionsReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ export class ConnectionOptionsReader {
connectionOptions = new ConnectionOptionsEnvReader().read();

} else if (foundFileFormat === "js") {
connectionOptions = PlatformTools.load(configFile);
connectionOptions = await PlatformTools.load(configFile);

} else if (foundFileFormat === "ts") {
connectionOptions = PlatformTools.load(configFile);
connectionOptions = await PlatformTools.load(configFile);

} else if (foundFileFormat === "json") {
connectionOptions = PlatformTools.load(configFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = Promise.resolve({
type: "sqlite",
name: "file",
database: "test-js-async"
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ describe("ConnectionOptionsReader", () => {
expect(fileOptions.database).to.have.string("/test-js");
});

it("properly loads asynchronous config with specified file path", async () => {
const connectionOptionsReader = new ConnectionOptionsReader({ root: __dirname, configName: "configs/test-path-config-async.js" });
const fileOptions: ConnectionOptions = await connectionOptionsReader.get("file");
expect(fileOptions.database).to.have.string("/test-js-async");
});

// TODO This test requires the configs/.env file be moved to the matching directory in build/compiled
it.skip("properly loads config from .env file", async () => {
const connectionOptionsReader = new ConnectionOptionsReader({ root: __dirname, configName: "configs/.env" });
Expand Down

0 comments on commit f9fdaee

Please sign in to comment.