|
|
@ -1,36 +1,10 @@ |
|
|
|
import { Connection } from "typeorm"; |
|
|
|
import connectToDatabase from "../database"; |
|
|
|
import { env, secret } from "@autoplex/utils"; |
|
|
|
import { InternalService } from "@autoplex/microservice"; |
|
|
|
import { DatabaseService, EntitySchemaTypes } from "@autoplex/database"; |
|
|
|
import * as entities from "../database/entities"; |
|
|
|
|
|
|
|
export default class Database extends InternalService |
|
|
|
export default class Database extends DatabaseService |
|
|
|
{ |
|
|
|
/** |
|
|
|
* The active database connection |
|
|
|
* The entities to use |
|
|
|
*/ |
|
|
|
public connection!: Connection; |
|
|
|
|
|
|
|
/** |
|
|
|
* The service name |
|
|
|
*/ |
|
|
|
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(); |
|
|
|
} |
|
|
|
public entities: EntitySchemaTypes[] = Object.values(entities); |
|
|
|
} |