|
1 | | -import 'reflect-metadata' |
| 1 | +// import 'reflect-metadata' |
2 | 2 | import { createConnection, createConnections, ConnectionOptions } from "typeorm"; |
3 | | -import { BlogConf, SharesConf, MongoConf } from '../../conf/db.conf' |
| 3 | +import { MysqlConf, MongoConf } from '../../conf/db.conf' |
4 | 4 | import { Entities, ShareEntities } from '../entities/mysql' |
5 | 5 | import { MongoEntities } from '../entities/mongo' |
6 | 6 | import { CONNECT_BLOG, CONNECT_MONGO, CONNECT_SHARES } from './dbUtils'; |
| 7 | +import stockHistoryDao from '../daos/StockHistoryDao' |
7 | 8 |
|
8 | 9 | const _PROD_ = process.env.NODE_ENV === 'production' |
9 | 10 |
|
10 | 11 | const connectDB = (): Promise<void> => { |
11 | 12 | const connectOptions = [ |
12 | | - {name: CONNECT_BLOG, entities: Entities, database: BlogConf.database}, |
13 | | - {name: CONNECT_SHARES, entities: ShareEntities, database: SharesConf.database} |
| 13 | + {name: CONNECT_BLOG, entities: Entities, database: CONNECT_BLOG}, |
| 14 | + {name: CONNECT_SHARES, entities: ShareEntities, database: CONNECT_SHARES} |
14 | 15 | ].map<ConnectionOptions>(db => { |
15 | 16 | return { |
16 | 17 | ...db, |
17 | 18 | type : 'mysql', |
18 | | - host : BlogConf.host, |
19 | | - port : BlogConf.port, |
20 | | - username : BlogConf.username, |
21 | | - password : BlogConf.password, |
| 19 | + host : MysqlConf.host, |
| 20 | + port : MysqlConf.port, |
| 21 | + username : MysqlConf.username, |
| 22 | + password : MysqlConf.password, |
22 | 23 | logging : _PROD_ ? false : true, |
23 | 24 | } |
24 | 25 | }) |
25 | 26 | return createConnections(connectOptions).then((connect) => { |
26 | | - console.log(`${connectOptions.length} mysql connected successfully!`) |
| 27 | + console.log(`${connectOptions.map(c => c.name).join()} ${connectOptions.length} mysql connected successfully!`) |
| 28 | + stockHistoryDao._getTotal() |
27 | 29 | }).catch((err) => { |
28 | 30 | console.log('mysql failed to connect!', err) |
29 | 31 | }) |
|
0 commit comments