initial
This commit is contained in:
37
src/helpers/orm.ts
Normal file
37
src/helpers/orm.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import config from 'config';
|
||||
import { DataSource } from "typeorm";
|
||||
import { User } from "../entity/users";
|
||||
import { TrialBalance } from '../entity/trial_balance';
|
||||
import { ILogObj, Logger } from 'tslog';
|
||||
import { LNKOLEK } from '../entity/lnkolek';
|
||||
import { CifAccount } from '../entity/cif_account';
|
||||
|
||||
export class OrmHelper {
|
||||
static DB: DataSource = null
|
||||
|
||||
static setup() {
|
||||
const log: Logger<ILogObj> = new Logger({ name: '[OrmHelper]', type: 'pretty' });
|
||||
|
||||
const engine: 'mysql' | 'postgres' = config.get("database.engine")
|
||||
|
||||
OrmHelper.DB = new DataSource({
|
||||
type: engine,
|
||||
host: config.get("database.host"),
|
||||
port: Number(config.get("database.port")),
|
||||
username: String(config.get("database.username")),
|
||||
password: String(config.get("database.password")),
|
||||
database: String(config.get("database.database")),
|
||||
synchronize: true,
|
||||
logging: true,
|
||||
entities: [User, TrialBalance, LNKOLEK, CifAccount],
|
||||
subscribers: [],
|
||||
migrations: [],
|
||||
})
|
||||
|
||||
OrmHelper.DB.initialize()
|
||||
.then(() => {
|
||||
// here you can start to work with your database
|
||||
})
|
||||
.catch((error: any) => log.error(error))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user