mirror of
https://codeberg.org/buzzcode2007/FCC-Project-URLShortener.git
synced 2025-05-21 03:06:34 +00:00
Create the API and management
This commit is contained in:
parent
02709cccf4
commit
31e074a5a8
3 changed files with 213 additions and 0 deletions
21
scripts/database/management.js
Normal file
21
scripts/database/management.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
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};
|
Loading…
Add table
Add a link
Reference in a new issue