✨ generalize primary column to work with mongodb object id
This commit is contained in:
parent
b1c1b681b9
commit
7b63016872
BIN
api/package-lock.json
generated
BIN
api/package-lock.json
generated
Binary file not shown.
@ -92,7 +92,7 @@
|
|||||||
"i18next-node-fs-backend": "^2.1.3",
|
"i18next-node-fs-backend": "^2.1.3",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"lambert-server": "^1.2.10",
|
"lambert-server": "^1.2.10",
|
||||||
"missing-native-js-functions": "^1.2.15",
|
"missing-native-js-functions": "^1.2.16",
|
||||||
"mongoose": "^5.12.3",
|
"mongoose": "^5.12.3",
|
||||||
"mongoose-autopopulate": "^0.12.3",
|
"mongoose-autopopulate": "^0.12.3",
|
||||||
"mongoose-long": "^0.3.2",
|
"mongoose-long": "^0.3.2",
|
||||||
|
|||||||
BIN
bundle/package-lock.json
generated
BIN
bundle/package-lock.json
generated
Binary file not shown.
@ -56,7 +56,7 @@
|
|||||||
"async-exit-hook": "^2.0.1",
|
"async-exit-hook": "^2.0.1",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"missing-native-js-functions": "^1.2.15",
|
"missing-native-js-functions": "^1.2.16",
|
||||||
"nanocolors": "^0.2.12",
|
"nanocolors": "^0.2.12",
|
||||||
"node-os-utils": "^1.3.5",
|
"node-os-utils": "^1.3.5",
|
||||||
"tsconfig-paths": "^3.11.0"
|
"tsconfig-paths": "^3.11.0"
|
||||||
|
|||||||
BIN
cdn/package-lock.json
generated
BIN
cdn/package-lock.json
generated
Binary file not shown.
@ -54,7 +54,7 @@
|
|||||||
"jest": "^27.0.6",
|
"jest": "^27.0.6",
|
||||||
"lambert-db": "^1.2.3",
|
"lambert-db": "^1.2.3",
|
||||||
"lambert-server": "^1.2.8",
|
"lambert-server": "^1.2.8",
|
||||||
"missing-native-js-functions": "^1.2.15",
|
"missing-native-js-functions": "^1.2.16",
|
||||||
"multer": "^1.4.2",
|
"multer": "^1.4.2",
|
||||||
"nanocolors": "^0.2.12",
|
"nanocolors": "^0.2.12",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
|
|||||||
BIN
gateway/package-lock.json
generated
BIN
gateway/package-lock.json
generated
Binary file not shown.
@ -35,7 +35,7 @@
|
|||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"lambert-server": "^1.2.8",
|
"lambert-server": "^1.2.8",
|
||||||
"missing-native-js-functions": "^1.2.15",
|
"missing-native-js-functions": "^1.2.16",
|
||||||
"mongoose-autopopulate": "^0.12.3",
|
"mongoose-autopopulate": "^0.12.3",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"typeorm": "^0.2.37",
|
"typeorm": "^0.2.37",
|
||||||
|
|||||||
BIN
util/package-lock.json
generated
BIN
util/package-lock.json
generated
Binary file not shown.
@ -44,7 +44,7 @@
|
|||||||
"env-paths": "^2.2.1",
|
"env-paths": "^2.2.1",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"lambert-server": "^1.2.10",
|
"lambert-server": "^1.2.10",
|
||||||
"missing-native-js-functions": "^1.2.15",
|
"missing-native-js-functions": "^1.2.16",
|
||||||
"multer": "^1.4.3",
|
"multer": "^1.4.3",
|
||||||
"nanocolors": "^0.2.12",
|
"nanocolors": "^0.2.12",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
|
|||||||
@ -5,10 +5,8 @@ import {
|
|||||||
BeforeUpdate,
|
BeforeUpdate,
|
||||||
EntityMetadata,
|
EntityMetadata,
|
||||||
FindConditions,
|
FindConditions,
|
||||||
getConnection,
|
ObjectIdColumn,
|
||||||
getManager,
|
|
||||||
PrimaryColumn,
|
PrimaryColumn,
|
||||||
RemoveOptions,
|
|
||||||
} from "typeorm";
|
} from "typeorm";
|
||||||
import { Snowflake } from "../util/Snowflake";
|
import { Snowflake } from "../util/Snowflake";
|
||||||
import "missing-native-js-functions";
|
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 {
|
export class BaseClass extends BaseClassWithoutId {
|
||||||
@PrimaryColumn()
|
@PrimaryIdColumn()
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
assign(props: any = {}) {
|
assign(props: any = {}) {
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm";
|
import { Column, Entity } from "typeorm";
|
||||||
import { BaseClass, BaseClassWithoutId } from "./BaseClass";
|
import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import { Snowflake } from "../util/Snowflake";
|
import { Snowflake } from "../util/Snowflake";
|
||||||
|
|
||||||
@Entity("config")
|
@Entity("config")
|
||||||
export class ConfigEntity extends BaseClassWithoutId {
|
export class ConfigEntity extends BaseClassWithoutId {
|
||||||
@PrimaryColumn()
|
@PrimaryIdColumn()
|
||||||
key: string;
|
key: string;
|
||||||
|
|
||||||
@Column({ type: "simple-json", nullable: true })
|
@Column({ type: "simple-json", nullable: true })
|
||||||
@ -144,7 +144,7 @@ export interface ConfigValue {
|
|||||||
useDefaultAsOptimal: boolean;
|
useDefaultAsOptimal: boolean;
|
||||||
available: Region[];
|
available: Region[];
|
||||||
};
|
};
|
||||||
|
|
||||||
guild: {
|
guild: {
|
||||||
showAllGuildsInDiscovery: boolean;
|
showAllGuildsInDiscovery: boolean;
|
||||||
};
|
};
|
||||||
@ -299,7 +299,7 @@ export const DefaultConfigOptions: ConfigValue = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
guild: {
|
guild: {
|
||||||
showAllGuildsInDiscovery: false,
|
showAllGuildsInDiscovery: false,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm";
|
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
|
||||||
import { Member } from ".";
|
import { Member } from "./Member";
|
||||||
import { BaseClass } from "./BaseClass";
|
import { BaseClass, PrimaryIdColumn } from "./BaseClass";
|
||||||
import { Channel } from "./Channel";
|
import { Channel } from "./Channel";
|
||||||
import { Guild } from "./Guild";
|
import { Guild } from "./Guild";
|
||||||
import { User } from "./User";
|
import { User } from "./User";
|
||||||
@ -9,7 +9,7 @@ export const PublicInviteRelation = ["inviter", "guild", "channel"];
|
|||||||
|
|
||||||
@Entity("invites")
|
@Entity("invites")
|
||||||
export class Invite extends BaseClass {
|
export class Invite extends BaseClass {
|
||||||
@PrimaryColumn()
|
@PrimaryIdColumn()
|
||||||
code: string;
|
code: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
|
|||||||
@ -8,8 +8,6 @@ import {
|
|||||||
JoinTable,
|
JoinTable,
|
||||||
ManyToMany,
|
ManyToMany,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
OneToMany,
|
|
||||||
PrimaryColumn,
|
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
RelationId,
|
RelationId,
|
||||||
} from "typeorm";
|
} from "typeorm";
|
||||||
|
|||||||
@ -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 { BaseClass } from "./BaseClass";
|
||||||
import { Guild } from "./Guild";
|
import { Guild } from "./Guild";
|
||||||
import { User } from "./User";
|
import { User } from "./User";
|
||||||
|
|||||||
@ -24,7 +24,7 @@ export function initDatabase() {
|
|||||||
url: isSqlite ? undefined : dbConnectionString,
|
url: isSqlite ? undefined : dbConnectionString,
|
||||||
database: isSqlite ? dbConnectionString : undefined,
|
database: isSqlite ? dbConnectionString : undefined,
|
||||||
entities: Object.values(Models).filter((x) => x.constructor.name !== "Object"),
|
entities: Object.values(Models).filter((x) => x.constructor.name !== "Object"),
|
||||||
synchronize: true,
|
synchronize: type !== "mongodb",
|
||||||
logging: false,
|
logging: false,
|
||||||
cache: {
|
cache: {
|
||||||
duration: 1000 * 3, // cache all find queries for 3 seconds
|
duration: 1000 * 3, // cache all find queries for 3 seconds
|
||||||
|
|||||||
Reference in New Issue
Block a user