this.Pool
import mysql2 from 'mysql2/promise';
this.Pool = mysql2.createPool({
host : "1",
user : "2",
password : "3",
database : "4"
})
async createTable(table: string): Promise<void> {
await this.Pool.getConnection(async (connection) => {
await connection.query(`CREATE TABLE IF NOT EXISTS \`${table}\`(
a INT,
b INT
);`);
console.log("TABLE CREATED");
});
}
in this case, the code just waits to get promise
async createTable(table: string): Promise<void> {
await this.Pool.getConnection(async (connection) => {
return await connection.query(`CREATE TABLE IF NOT EXISTS \`${table}\`(
a INT,
b INT
);`);
console.log("TABLE CREATED");
});
}
but it just works..
this seems a bit different what I know. I know that Javascript automatically returns a Promise even if an asynchronous function does not return anything. is there something wrong in code or my knowledge?