@randombenj/db
Version:
Display, search and copy LXD-images using a web interface.
31 lines (27 loc) • 827 B
text/typescript
import { Injectable, Inject } from '@nestjs/common';
import { Connection, Repository } from 'typeorm';
()
export class DatabaseService {
/**
* Initializes the database service
* @param connection The connection, which gets injected
*/
constructor(('Connection') public connection: Connection) { }
/**
* Returns the repository of the given entity
* @param entity The database entity to get the repository from
*/
async getRepository(entity: any) {
return this.connection.getRepository(entity);
}
/**
* Closes the current connection, if it is
* connected
*/
async closeConnection() {
const connection = this.connection;
if (connection.isConnected) {
await this.connection.close();
}
}
}