|
|
@ -1,37 +0,0 @@ |
|
|
|
import { Connection } from "typeorm"; |
|
|
|
import { InternalService } from "@autoplex/microservice"; |
|
|
|
import connectToDatabase from "@autoplex/database"; |
|
|
|
import { env, secret } from "@autoplex/utils"; |
|
|
|
import Application from "@server/Application"; |
|
|
|
|
|
|
|
export default class Database extends InternalService<Application> |
|
|
|
{ |
|
|
|
/** |
|
|
|
* The active database connection |
|
|
|
*/ |
|
|
|
protected connection!: Connection; |
|
|
|
|
|
|
|
/** |
|
|
|
* The name of the service |
|
|
|
*/ |
|
|
|
public readonly NAME = "Database"; |
|
|
|
|
|
|
|
/** |
|
|
|
* Boot the database service |
|
|
|
*/ |
|
|
|
public async boot() { |
|
|
|
let host = env("DB_HOST"); |
|
|
|
let port = parseInt(env("DB_PORT")); |
|
|
|
let username = env("DB_USER"); |
|
|
|
let password = await secret(env("DB_PASSWORD_FILE")); |
|
|
|
let database = env("DB_DATABASE"); |
|
|
|
this.connection = await connectToDatabase(host, port, username, password, database); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Shutdown the database service |
|
|
|
*/ |
|
|
|
public async shutdown() { |
|
|
|
await this.connection.close(); |
|
|
|
} |
|
|
|
} |