node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

Can't get the database name after use db command

Open deepakaggarwal7 opened this issue 1 year ago • 0 comments

Consider the following code:

  const dbPool = mysql2.createPool({
     host: process.env.MYSQL_HOST,
     user: process.env.MYSQL_USER,
     password: process.env.MYSQL_PASSWORD,
   });
   await dbPool.query("create database test3");
   await dbPool.query("use test3");
   console.log((await dbPool.getConnection()).config.database);
   await dbPool.query("create table student(id int, name varchar(100))"); //always undefined
   await dbPool.query("drop database test3");
`console.log((await dbPool.getConnection()).config.database); ` is undefined but all further queries properly work which means pool is aware of the database. But, then why config.database is undefined. How can I get that value?

deepakaggarwal7 avatar Feb 24 '24 16:02 deepakaggarwal7