'"Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?" in Next.js API route
Before I was trying to connect mysql to server, I already connect mysql to my localhost and it works. But now I'm trying connect mysql to a server and it does not work. Can anyone solve this?
knexfile.js
module.exports = {
      development: {
        client: "mysql",
        connection: {
          host: process.env.DB_HOST,
          port: process.env.DB_PORT,
          user: process.env.DB_USER,
          password: process.env.DB_PASSWORD,
          database: process.env.DB_NAME,
        },
      },
};
knex.js
const knex = require("knex")({
      client: "mysql",
      connection: {
        host: process.env.DB_HOST,
        port: process.env.DB_PORT,
        user: process.env.DB_USER,
        password: process.env.DB_PASSWORD,
        database: process.env.DB_NAME,
      },
});
export default knex;
register api file
import knex from "../../../libs/knex";
import bcrypt from "bcryptjs";
import Chance from "chance";
var chance = new Chance();
const path = require("path");
export default async function hadler(req, res) {
  if (req.method !== "POST") return res.status(405).end();
  const { username, password } = req.body;
  const salt = bcrypt.genSaltSync(10);
  const hashPassword = bcrypt.hashSync(password, salt);
  //: Check avaible username in database
  const checkUsername = await knex("users").where({ username }).first();
  if (checkUsername) return res.status(406).end();
  //: Insert data to database
  const key = chance.string({ length: 50 });
  const user = await knex("users").insert({
    username,
    password: hashPassword,
    userKey,
  });
  //: Create new table
  await knex.schema.createTable(`t_${username}`, function (table) {
    table.increments("id");
    table.string("title");
    table.string("subtitle");
    table.string("content");
    table.timestamps(true, true);
  });
  res.status(200).json({
    message: "Registered succesfully!",
    data: req.body,
    tableName: `t_${username}`,
  });
}
							
						Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|
