summary refs log tree commit diff
path: root/src/Server.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-14 19:01:41 +0100
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-14 19:01:41 +0100
commita94f7c76172d83b95f43b059b9a5af4299eb2f8d (patch)
treeab0ea2cf4c90d927747701abcc80a95d2d75721f /src/Server.ts
parentutil function to emit event (diff)
downloadserver-a94f7c76172d83b95f43b059b9a5af4299eb2f8d.tar.xz
switch to mongoose
Diffstat (limited to 'src/Server.ts')
-rw-r--r--src/Server.ts15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/Server.ts b/src/Server.ts

index b561f94e..fa4111db 100644 --- a/src/Server.ts +++ b/src/Server.ts
@@ -1,5 +1,6 @@ import "missing-native-js-functions"; import fs from "fs/promises"; +import { Connection } from "mongoose"; import { Server, ServerOptions } from "lambert-server"; import { Authentication, GlobalRateLimit } from "./middlewares/"; import Config from "./util/Config"; @@ -29,8 +30,20 @@ export class DiscordServer extends Server { super({ ...opts, errorHandler: false, jsonBody: false }); } + async setupSchema() { + await db.collection("users").createIndex({ id: 1 }, { unique: true }); + await db.collection("messages").createIndex({ id: 1 }, { unique: true }); + await db.collection("channels").createIndex({ id: 1 }, { unique: true }); + await db.collection("guilds").createIndex({ id: 1 }, { unique: true }); + await db.collection("members").createIndex({ id: 1 }, { unique: true }); + await db.collection("roles").createIndex({ id: 1 }, { unique: true }); + await db.collection("emojis").createIndex({ id: 1 }, { unique: true }); + } + async start() { - await db.init(); + // @ts-ignore + await (db as Promise<Connection>); + await this.setupSchema(); console.log("[DB] connected"); await Promise.all([Config.init()]);