update
This commit is contained in:
@ -1,34 +1,69 @@
|
||||
import config from 'config';
|
||||
import { DataSource } from "typeorm";
|
||||
import { Application, Menu, User, UserActivity, UserRefreshToken, UserRole } from "entity";
|
||||
import { ILogObj, Logger } from 'tslog';
|
||||
import config from "config"
|
||||
import { DataSource } from "typeorm"
|
||||
import {
|
||||
Aldeia,
|
||||
Suco,
|
||||
Munisipo,
|
||||
Administrativu,
|
||||
Nationality,
|
||||
Application, //
|
||||
Menu,
|
||||
User,
|
||||
UserActivity,
|
||||
UserRefreshToken,
|
||||
UserRole,
|
||||
HrmsAirport,
|
||||
HrmsPosition,
|
||||
HrmsEmployee,
|
||||
HrmsDepartment,
|
||||
HrmsShift,
|
||||
} from "entity"
|
||||
import { ILogObj, Logger } from "tslog"
|
||||
|
||||
export class OrmHelper {
|
||||
static DB: DataSource = null
|
||||
static DB: DataSource = null
|
||||
|
||||
static setup() {
|
||||
const log: Logger<ILogObj> = new Logger({ name: '[OrmHelper]', type: 'pretty' });
|
||||
static setup() {
|
||||
const log: Logger<ILogObj> = new Logger({ name: "[OrmHelper]", type: "pretty" })
|
||||
|
||||
const engine: 'mysql' | 'postgres' = config.get("database.engine")
|
||||
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: config.get('database.logging'),
|
||||
entities: [User, UserRole, UserActivity, UserRefreshToken, Menu, Application],
|
||||
subscribers: [],
|
||||
migrations: [],
|
||||
})
|
||||
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: config.get("database.logging"),
|
||||
entities: [
|
||||
Aldeia,
|
||||
Suco,
|
||||
Munisipo,
|
||||
Administrativu,
|
||||
Nationality,
|
||||
User, //
|
||||
UserRole,
|
||||
UserActivity,
|
||||
UserRefreshToken,
|
||||
Menu,
|
||||
Application,
|
||||
Nationality,
|
||||
HrmsDepartment, //
|
||||
HrmsAirport,
|
||||
HrmsPosition,
|
||||
HrmsShift,
|
||||
HrmsEmployee,
|
||||
],
|
||||
subscribers: [],
|
||||
migrations: [],
|
||||
})
|
||||
|
||||
OrmHelper.DB.initialize()
|
||||
.then(() => {
|
||||
// here you can start to work with your database
|
||||
})
|
||||
.catch((error: any) => log.error(error))
|
||||
}
|
||||
}
|
||||
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