-
-
Save GendelfLugansk/d37588f2854cbe64269657c4d933f163 to your computer and use it in GitHub Desktop.
Just some code example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param dbType {('mysql'|'mssql'|'postgresql')} Type of the db | |
* @constructor | |
*/ | |
function DB(dbType) { | |
if (['mysql', 'mssql', 'postgresql'].indexOf(dbType) === -1) { | |
throw new Error('Unsupported database type'); | |
} | |
/** | |
* @type {('mysql'|'mssql'|'postgresql')} Type of the db | |
* @private | |
*/ | |
this._dbType = dbType; | |
this.connect = function () { | |
console.log(`Connecting to ${this._dbType}`); | |
return new Promise(resolve => { | |
setTimeout(() => { | |
console.log(`Connected to ${this._dbType}`); | |
this.connectedAt = new Date(); | |
resolve(); | |
}, 500); | |
}); | |
} | |
} | |
export default DB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DB from './db'; | |
const db = new DB("mssql"); | |
db.connect(); | |
console.log(db.connectedAt); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment