I am trying to pass a mysql2 connection pool to the Knex client by following the official documentation. However, the query execution seems to get stuck. Even though the insert query successfully inserts the data, it doesn’t return anything and the code remains stuck. How can I resolve this issue?
Here’s my code:
import knex from "knex";
import mysql from "mysql2/promise";
export const mysqlPool = mysql.createPool({
host: "localhost",
user: "user",
password: "pass",
database: "db",
});
const knexC = knex({
client: "mysql2",
});
(async () => {
// passing the pool to knex
const res = await knexC("user").connection(mysqlPool).select("*");
console.log(res);
// pass a connection to knex
const connection = await mysqlPool.getConnection();
const newRes = await knexC("user").connection(connection).select("*");
console.log(newRes);
})();
New contributor
shariq arif is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.