summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-16 21:16:56 +0100
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-02-16 21:16:56 +0100
commit57746da87206f31c8612b975df37305fb2a5e0b7 (patch)
treeb3f1774d3e4921571e95a40035875ad4b01da145 /src
parent:bug: fix database (diff)
downloadserver-57746da87206f31c8612b975df37305fb2a5e0b7.tar.xz
:bug: fix database
Diffstat (limited to '')
-rw-r--r--src/models/Channel.ts4
-rw-r--r--src/models/Emoji.ts4
-rw-r--r--src/models/Event.ts4
-rw-r--r--src/models/Guild.ts4
-rw-r--r--src/models/Invite.ts4
-rw-r--r--src/models/Member.ts4
-rw-r--r--src/models/Message.ts4
-rw-r--r--src/models/Role.ts4
-rw-r--r--src/models/User.ts4
-rw-r--r--src/models/VoiceState.ts4
-rw-r--r--src/util/Database.ts7
11 files changed, 35 insertions, 12 deletions
diff --git a/src/models/Channel.ts b/src/models/Channel.ts
index 57e75f26..3ab571e7 100644
--- a/src/models/Channel.ts
+++ b/src/models/Channel.ts
@@ -1,4 +1,5 @@
 import { Schema, model, Types, Document } from "mongoose";
+import db from "../util/Database";
 
 export interface AnyChannel extends Channel, DMChannel, TextChannel, VoiceChannel {}
 
@@ -31,7 +32,8 @@ export const ChannelSchema = new Schema({
 	],
 });
 
-export const ChannelModel = model<ChannelDocument>("Channel", ChannelSchema, "channels");
+// @ts-ignore
+export const ChannelModel = db.model<ChannelDocument>("Channel", ChannelSchema, "channels");
 
 export interface Channel {
 	id: bigint;
diff --git a/src/models/Emoji.ts b/src/models/Emoji.ts
index bbed9323..298737e5 100644
--- a/src/models/Emoji.ts
+++ b/src/models/Emoji.ts
@@ -1,4 +1,5 @@
 import { Schema, model, Types, Document } from "mongoose";
+import db from "../util/Database";
 
 export interface Emoji extends Document {
 	id: bigint;
@@ -24,4 +25,5 @@ export const EmojiSchema = new Schema({
 	roles: [Types.Long],
 });
 
-export const EmojiModel = model<Emoji>("Emoji", EmojiSchema, "emojis");
+// @ts-ignore
+export const EmojiModel = db.model<Emoji>("Emoji", EmojiSchema, "emojis");
diff --git a/src/models/Event.ts b/src/models/Event.ts
index 515c6119..15b37f55 100644
--- a/src/models/Event.ts
+++ b/src/models/Event.ts
@@ -11,6 +11,7 @@ import { VoiceState } from "./VoiceState";
 import { ApplicationCommand } from "./Application";
 import { Interaction } from "./Interaction";
 import { Schema, model, Types, Document } from "mongoose";
+import db from "../util/Database";
 
 export interface Event {
 	guild_id?: bigint;
@@ -32,7 +33,8 @@ export const EventSchema = new Schema({
 	data: Object,
 });
 
-export const EventModel = model<EventDocument>("Event", EventSchema, "events");
+// @ts-ignore
+export const EventModel = db.model<EventDocument>("Event", EventSchema, "events");
 
 // ! Custom Events that shouldn't get sent to the client but processed by the server
 
diff --git a/src/models/Guild.ts b/src/models/Guild.ts
index a6ed6773..8eb7533f 100644
--- a/src/models/Guild.ts
+++ b/src/models/Guild.ts
@@ -1,4 +1,5 @@
 import { Schema, model, Types, Document } from "mongoose";
+import db from "../util/Database";
 
 export interface GuildDocument extends Document, Guild {
 	id: bigint;
@@ -86,4 +87,5 @@ export const GuildSchema = new Schema({
 	widget_enabled: Boolean,
 });
 
-export const GuildModel = model<GuildDocument>("Guild", GuildSchema, "guilds");
+// @ts-ignore
+export const GuildModel = db.model<GuildDocument>("Guild", GuildSchema, "guilds");
diff --git a/src/models/Invite.ts b/src/models/Invite.ts
index b4dbb8bc..61619895 100644
--- a/src/models/Invite.ts
+++ b/src/models/Invite.ts
@@ -1,4 +1,5 @@
 import { Schema, model, Types, Document } from "mongoose";
+import db from "../util/Database";
 
 export interface Invite extends Document {
 	code: string;
@@ -73,4 +74,5 @@ export const InviteSchema = new Schema({
 	target_user_type: Number,
 });
 
-export const InviteModel = model<Invite>("Invite", InviteSchema, "invites");
+// @ts-ignore
+export const InviteModel = db.model<Invite>("Invite", InviteSchema, "invites");
diff --git a/src/models/Member.ts b/src/models/Member.ts
index c4d3a598..422a83cf 100644
--- a/src/models/Member.ts
+++ b/src/models/Member.ts
@@ -1,5 +1,6 @@
 import { PublicUser } from "./User";
 import { Schema, model, Types, Document } from "mongoose";
+import db from "../util/Database";
 
 export interface Member {
 	id: bigint;
@@ -75,7 +76,8 @@ export const MemberSchema = new Schema({
 	},
 });
 
-export const MemberModel = model<MemberDocument>("Member", MemberSchema, "members");
+// @ts-ignore
+export const MemberModel = db.model<MemberDocument>("Member", MemberSchema, "members");
 
 export interface PublicMember extends Omit<Member, "settings" | "id"> {
 	user: PublicUser;
diff --git a/src/models/Message.ts b/src/models/Message.ts
index 2f7323dc..6353c588 100644
--- a/src/models/Message.ts
+++ b/src/models/Message.ts
@@ -1,5 +1,6 @@
 import { Schema, model, Types, Document } from "mongoose";
 import { ChannelType } from "./Channel";
+import db from "../util/Database";
 
 export interface Message extends Document {
 	id: bigint;
@@ -227,4 +228,5 @@ export const MessageSchema = new Schema({
 	},
 });
 
-export const MessageModel = model<Message>("Message", MessageSchema, "messages");
+// @ts-ignore
+export const MessageModel = db.model<Message>("Message", MessageSchema, "messages");
diff --git a/src/models/Role.ts b/src/models/Role.ts
index a8d03373..fe716593 100644
--- a/src/models/Role.ts
+++ b/src/models/Role.ts
@@ -1,4 +1,5 @@
 import { Schema, model, Types, Document } from "mongoose";
+import db from "../util/Database";
 
 export interface Role {
 	id: bigint;
@@ -34,4 +35,5 @@ export const RoleSchema = new Schema({
 	},
 });
 
-export const RoleModel = model<RoleDocument>("Role", RoleSchema, "roles");
+// @ts-ignore
+export const RoleModel = db.model<RoleDocument>("Role", RoleSchema, "roles");
diff --git a/src/models/User.ts b/src/models/User.ts
index 6604cfca..5dfe320c 100644
--- a/src/models/User.ts
+++ b/src/models/User.ts
@@ -1,6 +1,7 @@
 import { Activity } from "./Activity";
 import { ClientStatus, Status } from "./Status";
 import { Schema, model, Types, Document } from "mongoose";
+import db from "../util/Database";
 
 export interface User extends Document {
 	id: bigint;
@@ -202,4 +203,5 @@ export const UserSchema = new Schema({
 	},
 });
 
-export const UserModel = model<User>("User", UserSchema, "users");
+// @ts-ignore
+export const UserModel = db.model<User>("User", UserSchema, "users");
diff --git a/src/models/VoiceState.ts b/src/models/VoiceState.ts
index 8ac5ae19..30439feb 100644
--- a/src/models/VoiceState.ts
+++ b/src/models/VoiceState.ts
@@ -1,5 +1,6 @@
 import { PublicMember } from "./Member";
 import { Schema, model, Types, Document } from "mongoose";
+import db from "../util/Database";
 
 export interface VoiceState extends Document {
 	guild_id?: bigint;
@@ -29,4 +30,5 @@ export const VoiceSateSchema = new Schema({
 	suppress: Boolean, // whether this user is muted by the current user
 });
 
-export const VoiceStateModel = model<VoiceState>("VoiceState", VoiceSateSchema, "voicestates");
+// @ts-ignore
+export const VoiceStateModel = db.model<VoiceState>("VoiceState", VoiceSateSchema, "voicestates");
diff --git a/src/util/Database.ts b/src/util/Database.ts
index 1ebfbd12..2304378c 100644
--- a/src/util/Database.ts
+++ b/src/util/Database.ts
@@ -1,9 +1,12 @@
 import "./MongoBigInt";
-import mongoose, { Collection } from "mongoose";
+import mongoose, { Collection, Connection } from "mongoose";
 import { ChangeStream, ChangeEvent, Long } from "mongodb";
 import EventEmitter from "events";
+const uri = process.env.MONGO_URL || "mongodb://localhost:27017/fosscord?readPreference=secondaryPreferred";
 
-export default mongoose.connection;
+const connection = mongoose.createConnection(uri, { autoIndex: true });
+
+export default <Connection>connection;
 
 export interface MongooseCache {
 	on(event: "delete", listener: (id: string) => void): this;