itender/src/database/Database.ts
Tobias Hopp 2fe26ef34b Update
Took 10 minutes
2023-01-17 22:57:51 +01:00

29 lines
952 B
TypeScript

import * as Mongoose from "mongoose";
import debug from "debug";
import Ingredient from "./Ingredient";
import Drink from "./Drink";
import Container from "./Container";
// create a namespace for logging
const log = debug("itender:server");
export class Database {
// method to connect to the database
public static connect(): Promise<void> {
return new Promise(async (resolve, reject) => {
try {
//connect to mongodb using mongoose
await Mongoose.connect("mongodb://127.0.0.1:27017/iTender?retryWrites=true");
log("Connected to Database");
// Preload the schema for Ingredient, Drink and Container
Ingredient.find();
Drink.find();
Container.find();
resolve();
} catch (e) {
reject("Exception whilst connecting to Database " + e);
}
});
}
}