generalize primary column to work with mongodb object id

This commit is contained in:
Flam3rboy 2021-10-04 22:43:51 +02:00
parent b1c1b681b9
commit 7b63016872
16 changed files with 20 additions and 22 deletions

BIN
api/package-lock.json generated

Binary file not shown.

View File

@ -92,7 +92,7 @@
"i18next-node-fs-backend": "^2.1.3",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.10",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"mongoose": "^5.12.3",
"mongoose-autopopulate": "^0.12.3",
"mongoose-long": "^0.3.2",

BIN
bundle/package-lock.json generated

Binary file not shown.

View File

@ -56,7 +56,7 @@
"async-exit-hook": "^2.0.1",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"nanocolors": "^0.2.12",
"node-os-utils": "^1.3.5",
"tsconfig-paths": "^3.11.0"

BIN
cdn/package-lock.json generated

Binary file not shown.

View File

@ -54,7 +54,7 @@
"jest": "^27.0.6",
"lambert-db": "^1.2.3",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"multer": "^1.4.2",
"nanocolors": "^0.2.12",
"node-fetch": "^2.6.1",

Binary file not shown.

View File

@ -35,7 +35,7 @@
"dotenv": "^8.2.0",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.8",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"mongoose-autopopulate": "^0.12.3",
"node-fetch": "^2.6.1",
"typeorm": "^0.2.37",

BIN
util/package-lock.json generated

Binary file not shown.

View File

@ -44,7 +44,7 @@
"env-paths": "^2.2.1",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.10",
"missing-native-js-functions": "^1.2.15",
"missing-native-js-functions": "^1.2.16",
"multer": "^1.4.3",
"nanocolors": "^0.2.12",
"node-fetch": "^2.6.1",

View File

@ -5,10 +5,8 @@ import {
BeforeUpdate,
EntityMetadata,
FindConditions,
getConnection,
getManager,
ObjectIdColumn,
PrimaryColumn,
RemoveOptions,
} from "typeorm";
import { Snowflake } from "../util/Snowflake";
import "missing-native-js-functions";
@ -117,8 +115,10 @@ export class BaseClassWithoutId extends BaseEntity {
// }
}
export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb") ? ObjectIdColumn : PrimaryColumn;
export class BaseClass extends BaseClassWithoutId {
@PrimaryColumn()
@PrimaryIdColumn()
id: string;
assign(props: any = {}) {

View File

@ -1,11 +1,11 @@
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm";
import { BaseClass, BaseClassWithoutId } from "./BaseClass";
import { Column, Entity } from "typeorm";
import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass";
import crypto from "crypto";
import { Snowflake } from "../util/Snowflake";
@Entity("config")
export class ConfigEntity extends BaseClassWithoutId {
@PrimaryColumn()
@PrimaryIdColumn()
key: string;
@Column({ type: "simple-json", nullable: true })
@ -144,7 +144,7 @@ export interface ConfigValue {
useDefaultAsOptimal: boolean;
available: Region[];
};
guild: {
showAllGuildsInDiscovery: boolean;
};
@ -299,7 +299,7 @@ export const DefaultConfigOptions: ConfigValue = {
},
],
},
guild: {
showAllGuildsInDiscovery: false,
},

View File

@ -1,6 +1,6 @@
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm";
import { Member } from ".";
import { BaseClass } from "./BaseClass";
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { Member } from "./Member";
import { BaseClass, PrimaryIdColumn } from "./BaseClass";
import { Channel } from "./Channel";
import { Guild } from "./Guild";
import { User } from "./User";
@ -9,7 +9,7 @@ export const PublicInviteRelation = ["inviter", "guild", "channel"];
@Entity("invites")
export class Invite extends BaseClass {
@PrimaryColumn()
@PrimaryIdColumn()
code: string;
@Column()

View File

@ -8,8 +8,6 @@ import {
JoinTable,
ManyToMany,
ManyToOne,
OneToMany,
PrimaryColumn,
PrimaryGeneratedColumn,
RelationId,
} from "typeorm";

View File

@ -1,4 +1,4 @@
import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm";
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { User } from "./User";

View File

@ -24,7 +24,7 @@ export function initDatabase() {
url: isSqlite ? undefined : dbConnectionString,
database: isSqlite ? dbConnectionString : undefined,
entities: Object.values(Models).filter((x) => x.constructor.name !== "Object"),
synchronize: true,
synchronize: type !== "mongodb",
logging: false,
cache: {
duration: 1000 * 3, // cache all find queries for 3 seconds