I'm having trouble connecting my Telegram bot to the database using knex. I am working with MySQL, and I have already created the database and tables which are visible on the /phpMyAdmin page. The credentials used for accessing the database in my code are correct. I've carefully checked the configuration data and everything seems right. Below is the code snippet for creating the client:
this.knex = knex({
client: "mysql",
connection: {
host: this.config.HOST,
port: this.config.PORT,
user: this.config.USERNAME,
password: this.config.PASSWORD,
database: this.config.DATABASE,
},
//I added the line below suspecting a pool error, but it didn't resolve the issue
pool: { min: 0, max: 7 },
});
This code resides inside my class. Here's the method I'm attempting to call (None of console.logs seem to work):
async getManagers() {
const managers = await this.knex
.select("*")
.from("users")
.where("isManager", 1)
.then((data) => {
console.log(data);
});
console.log(managers);
}
I am certain that I have a table named user
with a field isManager
in it.
Here's how I invoke it:
const dbDataService = new DBDataService(databaseConfiguration);
dbDataService.getManagers();
However, I keep encountering the following error message:
(node:31227) UnhandledPromiseRejectionWarning: KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
at Client_MySQL.acquireConnection (/project/node_modules/knex/lib/client.js:348:26)
(node:31227) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
If needed, here is my list of dependencies:
"dependencies": {
"dotenv": "^11.0.0",
"mysql": "^2.1.0",
"knex": "^0.21.1",
"log4js": "^6.3.0",
"node-telegram-bot-api": "^0.56.0"
}
I have experimented with different versions of knex (1.0.1) but still face the same error. I've dedicated an entire day trying to troubleshoot this problem, yet I haven't been able to resolve it. Any assistance would be greatly appreciated. Thank you.