Browse Source

Use the Database package in the torrent client

dev
David Ludwig 4 years ago
parent
commit
e95fe3e4f3
3 changed files with 8 additions and 33 deletions
  1. +1
    -0
      services/torrent/package.json
  2. +2
    -2
      services/torrent/src/database/entities/index.ts
  3. +5
    -31
      services/torrent/src/services/Database.ts

+ 1
- 0
services/torrent/package.json View File

@ -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",


+ 2
- 2
services/torrent/src/database/entities/index.ts View File

@ -1,5 +1,5 @@
import Torrent from "./Torrent";
export default [
export {
Torrent
];
};

+ 5
- 31
services/torrent/src/services/Database.ts View File

@ -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);
}

Loading…
Cancel
Save