Skip to content

Commit f9fdaee

Browse files
StevenGBrownpleerock
authored andcommitted
feat: asynchronous ormconfig support (#5048)
This allows a Promise to be returned from a js or ts ormconfig file. Closes: #4149
1 parent f0fd192 commit f9fdaee

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/connection/ConnectionOptionsReader.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ export class ConnectionOptionsReader {
108108
connectionOptions = new ConnectionOptionsEnvReader().read();
109109

110110
} else if (foundFileFormat === "js") {
111-
connectionOptions = PlatformTools.load(configFile);
111+
connectionOptions = await PlatformTools.load(configFile);
112112

113113
} else if (foundFileFormat === "ts") {
114-
connectionOptions = PlatformTools.load(configFile);
114+
connectionOptions = await PlatformTools.load(configFile);
115115

116116
} else if (foundFileFormat === "json") {
117117
connectionOptions = PlatformTools.load(configFile);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = Promise.resolve({
2+
type: "sqlite",
3+
name: "file",
4+
database: "test-js-async"
5+
});

test/functional/connection-options-reader/connection-options-reader.ts

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ describe("ConnectionOptionsReader", () => {
3131
expect(fileOptions.database).to.have.string("/test-js");
3232
});
3333

34+
it("properly loads asynchronous config with specified file path", async () => {
35+
const connectionOptionsReader = new ConnectionOptionsReader({ root: __dirname, configName: "configs/test-path-config-async.js" });
36+
const fileOptions: ConnectionOptions = await connectionOptionsReader.get("file");
37+
expect(fileOptions.database).to.have.string("/test-js-async");
38+
});
39+
3440
// TODO This test requires the configs/.env file be moved to the matching directory in build/compiled
3541
it.skip("properly loads config from .env file", async () => {
3642
const connectionOptionsReader = new ConnectionOptionsReader({ root: __dirname, configName: "configs/.env" });

0 commit comments

Comments
 (0)