Skip to content

Commit 2298438

Browse files
committed
Load options by type orm (e.g. env vars, config files) and then overwrite with env.ts
1 parent 5fdf995 commit 2298438

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/loaders/typeormLoader.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { MicroframeworkLoader, MicroframeworkSettings } from 'microframework-w3tec';
2-
import { createConnection } from 'typeorm';
2+
import { createConnection, getConnectionOptions } from 'typeorm';
33

44
import { env } from '../env';
55

66
export const typeormLoader: MicroframeworkLoader = async (settings: MicroframeworkSettings | undefined) => {
77

8-
const connection = await createConnection({
8+
const loadedConnectionOptions = await getConnectionOptions();
9+
10+
const connectionOptions = Object.assign(loadedConnectionOptions, {
911
type: env.db.type as any, // See createConnection options for valid types
1012
host: env.db.host,
1113
port: env.db.port,
@@ -18,6 +20,8 @@ export const typeormLoader: MicroframeworkLoader = async (settings: Microframewo
1820
migrations: env.app.dirs.migrations,
1921
});
2022

23+
const connection = await createConnection(connectionOptions);
24+
2125
if (settings) {
2226
settings.setData('connection', connection);
2327
settings.onShutdown(() => connection.close());

0 commit comments

Comments
 (0)