-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnection.ts
33 lines (29 loc) · 905 Bytes
/
connection.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { createConnection, getConnection } from "typeorm";
const connection = {
async create(testConnection: boolean) {
let entitiesPath = testConnection ? "entity/**/*.entity.ts" : "dist/**/*.entity.js"
await createConnection({
type: "postgres",
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT || "5433"),
username: process.env.DB_USERNAME,
password: process.env.PASSWORD,
database: process.env.DATABASE_NAME,
synchronize: true,
logging: false,
entities: [
entitiesPath
],
migrations: [
"migration/*.ts"
],
subscribers: [
"subscriber/*.ts"
]
});
},
async close() {
await getConnection().close();
}
}
export { connection };