mirror of
https://github.com/spacebarchat/server.git
synced 2026-09-17 03:45:11 +00:00
27 lines
661 B
TypeScript
27 lines
661 B
TypeScript
import "reflect-metadata";
|
|
import { BaseEntity, ObjectIdColumn, PrimaryColumn, SaveOptions } from "typeorm";
|
|
import { Snowflake } from "../util/Snowflake";
|
|
|
|
export class BaseClassWithoutId extends BaseEntity {
|
|
constructor() {
|
|
super();
|
|
}
|
|
}
|
|
|
|
export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb") ? ObjectIdColumn : PrimaryColumn;
|
|
|
|
export class BaseClass extends BaseClassWithoutId {
|
|
@PrimaryIdColumn()
|
|
id: string;
|
|
|
|
constructor() {
|
|
super();
|
|
if (!this.id) this.id = Snowflake.generate();
|
|
}
|
|
|
|
save(options?: SaveOptions | undefined): Promise<this> {
|
|
if (!this.id) this.id = Snowflake.generate();
|
|
return super.save(options);
|
|
}
|
|
}
|