mirror of
https://codeberg.org/buzzcode2007/FCC-Project-URLShortener.git
synced 2025-05-21 03:06:34 +00:00
21 lines
No EOL
706 B
JavaScript
21 lines
No EOL
706 B
JavaScript
const Mongoose = require(`mongoose`);
|
|
const CustomErrors = require(`../utilities/errors`).CustomErrors;
|
|
|
|
class DBManagement {
|
|
/*
|
|
Begin the connection.
|
|
|
|
@param {string} DOMAIN the domain
|
|
@param {string} DBNAME the database name
|
|
*/
|
|
constructor (DOMAIN, DBNAME) {
|
|
const throwError = (ERROR) => {throw ERROR;};
|
|
|
|
this[`state`] = Mongoose.connect(`mongodb://${DOMAIN}/${(DBNAME) ? DBNAME : ""}`, { useNewUrlParser: true, useUnifiedTopology: true }).then((CONNECTION) => {
|
|
this[`connection`] = CONNECTION.connection;
|
|
console.log(`Connection successful.`);
|
|
}).catch(throwError);
|
|
};
|
|
}
|
|
|
|
module.exports = {DBManagement}; |