This commit is contained in:
2024-11-30 13:24:46 +07:00
commit 3e32e5869e
30 changed files with 1196 additions and 0 deletions

37
src/helpers/orm.ts Normal file
View 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))
}
}