From 366c4935a42d5056c51cdbd7c82c2674f1b8b128 Mon Sep 17 00:00:00 2001 From: Samuel <34555296+Flam3rboy@users.noreply.github.com> Date: Sat, 18 Mar 2023 04:11:48 +0100 Subject: feat: Database Query Cache --- src/util/entities/BaseClass.ts | 44 +++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'src/util/entities/BaseClass.ts') diff --git a/src/util/entities/BaseClass.ts b/src/util/entities/BaseClass.ts index 445b3fc9..87b394c5 100644 --- a/src/util/entities/BaseClass.ts +++ b/src/util/entities/BaseClass.ts @@ -25,16 +25,12 @@ import { PrimaryColumn, } from "typeorm"; import { Snowflake } from "../util/Snowflake"; -import { getDatabase } from "../util/Database"; import { OrmUtils } from "../imports/OrmUtils"; +import { getDatabase } from "../util"; export class BaseClassWithoutId extends BaseEntity { - private get construct() { - return this.constructor; - } - - private get metadata() { - return getDatabase()?.getMetadata(this.construct); + public get metadata() { + return getDatabase()?.getMetadata(this.constructor); } assign(props: object) { @@ -61,8 +57,23 @@ export class BaseClassWithoutId extends BaseEntity { ), ); } +} + +export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb") + ? ObjectIdColumn + : PrimaryColumn; + +export class BaseClassWithId extends BaseClassWithoutId { + @PrimaryIdColumn() + id: string = Snowflake.generate(); + + @BeforeUpdate() + @BeforeInsert() + _do_validate() { + if (!this.id) this.id = Snowflake.generate(); + } - static increment( + static increment( conditions: FindOptionsWhere, propertyPath: string, value: number | string, @@ -71,7 +82,7 @@ export class BaseClassWithoutId extends BaseEntity { return repository.increment(conditions, propertyPath, value); } - static decrement( + static decrement( conditions: FindOptionsWhere, propertyPath: string, value: number | string, @@ -80,18 +91,3 @@ export class BaseClassWithoutId extends BaseEntity { return repository.decrement(conditions, propertyPath, value); } } - -export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb") - ? ObjectIdColumn - : PrimaryColumn; - -export class BaseClass extends BaseClassWithoutId { - @PrimaryIdColumn() - id: string = Snowflake.generate(); - - @BeforeUpdate() - @BeforeInsert() - _do_validate() { - if (!this.id) this.id = Snowflake.generate(); - } -} -- cgit 1.5.1