#MongoDB
7 messages · Page 1 of 1 (latest)
export class DatabaseService {
private Database;
private reservationQueue: Booking[] = [];
private isProcessingQueue: boolean = false;
constructor(databaseId: string) {
if (databaseId === process.env.GUILDSERVER_GODS) {
this.Database = GODSDB;
} else if (databaseId === process.env.GUILDSERVER_REFUGIA) {
this.Database = REFUGIADB;
} else {
throw new Error(`Unknown database ID: ${databaseId}`);
}
}
public async enqueueReservation(reservation: Booking) {
this.reservationQueue.push(reservation);
console.log("adding reservation to queue");
if (!this.isProcessingQueue) {
await this.processReservationQueue();
} else {
setTimeout(async () => {
console.log("End waiting after 3 seconds!");
await this.processReservationQueue();
}, 3000);
}
}
``` this is my solution so far but it looks shiit
i think the problem is that, the databaseService is created in the command. so i think i must provide the connections first then i can collect everything in the queue. how do i determine the Guild before a command happens?
Why implement it in js when transactions on databases exist for this exact use case?
well then i dont understand how it works, my problem is DatabaseService gets created when a slahscommand happens
how would i do that with mongoose?
so that means 2 ppl hitting the command at the same time. i create 2 transactions