I'm just learning to use promises for MySQL in NodeJS. I'm using the following code to wrap my MySQL queries in Promises.
const mysql = require( 'mysql' );
let config = {
host : 'localhost',
user : 'myuser',
password : 'mypassword',
database: 'mydatabase'
};
class Database {
constructor( config ) {
this.connection = mysql.createConnection( config );
}
query( sql, args ) {
return new Promise( ( resolve, reject ) => {
this.database.query( sql, args, ( err, rows ) => {
if ( err )
return reject( err );
resolve( rows );
} );
} );
}
close() {
return new Promise( ( resolve, reject ) => {
this.connection.end( err => {
if ( err )
return reject( err );
resolve();
} );
} );
}
}
let mydb = new DataBase(config);
But I'm getting the following error in my console;
let mydb = new DataBase;
^
ReferenceError: DataBase is not defined
I've tried using both uppercase and lowercase for DataBase. I've tried with and without new. But I don't understand why I'm getting this error.
What am I doing wrong?
The spelling just needs to match. Right now you have Database
and DataBase