Switch to TypeORM's DataSource API (#299)
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
- Switch to TypeORM's DataSource API, rather than using the now deprecated ormconfig.json - This will fix stage deployment not knowing how to deploy the database migrations #297 > **NOTE:** This change requires the deployment scripts to be updated, please update them on the server before merging Co-authored-by: Ethan Lane <ethan@vylpes.com> Reviewed-on: https://gitea.vylpes.xyz/RabbitLabs/vylbot-app/pulls/299
This commit is contained in:
parent
c2418381ea
commit
e6c845e3b2
37 changed files with 128 additions and 164 deletions
|
@ -1,5 +1,6 @@
|
|||
import { Column, DeepPartial, EntityTarget, getConnection, PrimaryColumn, ObjectLiteral, FindOptionsWhere } from "typeorm";
|
||||
import { Column, DeepPartial, EntityTarget, PrimaryColumn, ObjectLiteral, FindOptionsWhere } from "typeorm";
|
||||
import { v4 } from "uuid";
|
||||
import AppDataSource from "../database/dataSources/appDataSource";
|
||||
|
||||
export default class BaseEntity {
|
||||
constructor() {
|
||||
|
@ -21,25 +22,19 @@ export default class BaseEntity {
|
|||
public async Save<T extends BaseEntity>(target: EntityTarget<T>, entity: DeepPartial<T>): Promise<void> {
|
||||
this.WhenUpdated = new Date();
|
||||
|
||||
const connection = getConnection();
|
||||
|
||||
const repository = connection.getRepository<T>(target);
|
||||
const repository = AppDataSource.getRepository<T>(target);
|
||||
|
||||
await repository.save(entity);
|
||||
}
|
||||
|
||||
public static async Remove<T extends BaseEntity>(target: EntityTarget<T>, entity: T): Promise<void> {
|
||||
const connection = getConnection();
|
||||
|
||||
const repository = connection.getRepository<T>(target);
|
||||
const repository = AppDataSource.getRepository<T>(target);
|
||||
|
||||
await repository.remove(entity);
|
||||
}
|
||||
|
||||
public static async FetchAll<T extends BaseEntity>(target: EntityTarget<T>, relations?: string[]): Promise<T[]> {
|
||||
const connection = getConnection();
|
||||
|
||||
const repository = connection.getRepository<T>(target);
|
||||
const repository = AppDataSource.getRepository<T>(target);
|
||||
|
||||
const all = await repository.find({ relations: relations || [] });
|
||||
|
||||
|
@ -47,9 +42,7 @@ export default class BaseEntity {
|
|||
}
|
||||
|
||||
public static async FetchOneById<T extends BaseEntity>(target: EntityTarget<T>, id: string, relations?: string[]): Promise<T | null> {
|
||||
const connection = getConnection();
|
||||
|
||||
const repository = connection.getRepository<T>(target);
|
||||
const repository = AppDataSource.getRepository<T>(target);
|
||||
|
||||
const single = await repository.findOne({ where: ({ Id: id } as FindOptionsWhere<T>), relations: relations || {} });
|
||||
|
||||
|
@ -57,9 +50,7 @@ export default class BaseEntity {
|
|||
}
|
||||
|
||||
public static async Any<T extends ObjectLiteral>(target: EntityTarget<T>): Promise<boolean> {
|
||||
const connection = getConnection();
|
||||
|
||||
const repository = connection.getRepository<T>(target);
|
||||
const repository = AppDataSource.getRepository<T>(target);
|
||||
|
||||
const any = await repository.find();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue