@@ -4,26 +4,27 @@ import { createConnection, getConnectionOptions } from 'typeorm';
4
4
import { env } from '../env' ;
5
5
6
6
export const typeormLoader : MicroframeworkLoader = async ( settings : MicroframeworkSettings | undefined ) => {
7
+ if ( env . db . enabled ) {
8
+ const loadedConnectionOptions = await getConnectionOptions ( ) ;
7
9
8
- const loadedConnectionOptions = await getConnectionOptions ( ) ;
10
+ const connectionOptions = Object . assign ( loadedConnectionOptions , {
11
+ type : env . db . type as any , // See createConnection options for valid types
12
+ host : env . db . host ,
13
+ port : env . db . port ,
14
+ username : env . db . username ,
15
+ password : env . db . password ,
16
+ database : env . db . database ,
17
+ synchronize : env . db . synchronize ,
18
+ logging : env . db . logging ,
19
+ entities : env . app . dirs . entities ,
20
+ migrations : env . app . dirs . migrations ,
21
+ } ) ;
9
22
10
- const connectionOptions = Object . assign ( loadedConnectionOptions , {
11
- type : env . db . type as any , // See createConnection options for valid types
12
- host : env . db . host ,
13
- port : env . db . port ,
14
- username : env . db . username ,
15
- password : env . db . password ,
16
- database : env . db . database ,
17
- synchronize : env . db . synchronize ,
18
- logging : env . db . logging ,
19
- entities : env . app . dirs . entities ,
20
- migrations : env . app . dirs . migrations ,
21
- } ) ;
23
+ const connection = await createConnection ( connectionOptions ) ;
22
24
23
- const connection = await createConnection ( connectionOptions ) ;
24
-
25
- if ( settings ) {
26
- settings . setData ( 'connection' , connection ) ;
27
- settings . onShutdown ( ( ) => connection . close ( ) ) ;
25
+ if ( settings ) {
26
+ settings . setData ( 'connection' , connection ) ;
27
+ settings . onShutdown ( ( ) => connection . close ( ) ) ;
28
+ }
28
29
}
29
30
} ;
0 commit comments