From e95fe3e4f39dc44dc12873010b955337b9bee4d0 Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Fri, 7 May 2021 17:27:01 +0000 Subject: [PATCH] Use the Database package in the torrent client --- services/torrent/package.json | 1 + .../torrent/src/database/entities/index.ts | 4 +-- services/torrent/src/services/Database.ts | 36 +++---------------- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/services/torrent/package.json b/services/torrent/package.json index a6cb352..30a27c1 100644 --- a/services/torrent/package.json +++ b/services/torrent/package.json @@ -27,6 +27,7 @@ }, "dependencies": { "@autoplex-api/torrent": "^0.0.0", + "@autoplex/database": "^0.0.0", "@autoplex/ipc": "^0.0.0", "@autoplex/microservice": "^0.0.0", "@autoplex/utils": "^0.0.0", diff --git a/services/torrent/src/database/entities/index.ts b/services/torrent/src/database/entities/index.ts index 4eab70f..0a7b572 100644 --- a/services/torrent/src/database/entities/index.ts +++ b/services/torrent/src/database/entities/index.ts @@ -1,5 +1,5 @@ import Torrent from "./Torrent"; -export default [ +export { Torrent -]; +}; diff --git a/services/torrent/src/services/Database.ts b/services/torrent/src/services/Database.ts index 07828ee..6543f17 100644 --- a/services/torrent/src/services/Database.ts +++ b/services/torrent/src/services/Database.ts @@ -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); }