Skip to content

Instantly share code, notes, and snippets.

@GendelfLugansk
Created September 18, 2017 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GendelfLugansk/d37588f2854cbe64269657c4d933f163 to your computer and use it in GitHub Desktop.
Save GendelfLugansk/d37588f2854cbe64269657c4d933f163 to your computer and use it in GitHub Desktop.
Just some code example
/**
* @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;
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