errors on failed connection to help debugging, entities from database project in typeorm connection

This commit is contained in:
Ulf Gebhardt 2021-10-12 01:26:47 +02:00
parent 634733cd59
commit aa07ef2231
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
3 changed files with 27 additions and 5 deletions

View File

@ -1,6 +1,6 @@
import { createConnection, Connection } from 'typeorm' import { createConnection, Connection } from 'typeorm'
import CONFIG from '../config' import CONFIG from '../config'
import path from 'path' import { entities } from '@entity/index'
const connection = async (): Promise<Connection | null> => { const connection = async (): Promise<Connection | null> => {
let con = null let con = null
@ -13,10 +13,13 @@ const connection = async (): Promise<Connection | null> => {
username: CONFIG.DB_USER, username: CONFIG.DB_USER,
password: CONFIG.DB_PASSWORD, password: CONFIG.DB_PASSWORD,
database: CONFIG.DB_DATABASE, database: CONFIG.DB_DATABASE,
entities: [path.join(__dirname, 'entity', '*.{ts,js}')], entities,
synchronize: false, synchronize: false,
}) })
} catch (error) {} } catch (error) {
// eslint-disable-next-line no-console
console.log(error)
}
return con return con
} }

19
database/entity/index.ts Normal file
View File

@ -0,0 +1,19 @@
import { Balance } from './Balance'
import { Migration } from './Migration'
import { Transaction } from './Transaction'
import { TransactionCreation } from './TransactionCreation'
import { TransactionSendCoin } from './TransactionSendCoin'
import { User } from './User'
import { UserSetting } from './UserSetting'
import { UserTransaction } from './UserTransaction'
export const entities = [
Balance,
Migration,
Transaction,
TransactionCreation,
TransactionSendCoin,
User,
UserSetting,
UserTransaction,
]

View File

@ -1,6 +1,6 @@
import { createConnection, Connection } from 'typeorm' import { createConnection, Connection } from 'typeorm'
import CONFIG from '../config' import CONFIG from '../config'
import path from 'path' import { entities } from '../../entity/index'
const connection = async (): Promise<Connection | null> => { const connection = async (): Promise<Connection | null> => {
let con = null let con = null
@ -13,7 +13,7 @@ const connection = async (): Promise<Connection | null> => {
username: CONFIG.DB_USER, username: CONFIG.DB_USER,
password: CONFIG.DB_PASSWORD, password: CONFIG.DB_PASSWORD,
database: CONFIG.DB_DATABASE, database: CONFIG.DB_DATABASE,
entities: [path.join(__dirname, '..', '..', 'entity', '*.{ts,js}')], entities,
synchronize: false, synchronize: false,
}) })
} catch (error) {} } catch (error) {}