我在升级到Node.js v16.4.0(从Node.js v12)后遇到以下错误。
我正在使用knex连接到数据库(postgres),并使用ORM-objection.js。
KnexTimeoutError:Knex:超时获取连接。池可能已满。您是否缺少.transacting(trx)调用?
请帮忙解决!
import Knex from "knex";
const getConnection = () => {
try {
return Knex({
client: 'pg',
connection: {
user: 'user',
password: 'password',
host: 'dbhost',
port: 5432,
database: 'dbname',
},
pool: {
min: 0,
max: 10,
idleTimeoutMillis: 10000,
acquireTimeoutMillis: 30000,
},
acquireConnectionTimeout: 2000,
});
}
catch (err) {
throw err;
}
}
const getTransaction = () => {
const con = getConnection();
const trx = con.transaction();
return trx;
}
db .raw('select 1') .then(() => { console.log('已连接到数据库 - OK') }) .catch(err => { console.error('使用${connection}连接到数据库失败:${err}') process.exit(1) })
使用Node14(也尝试过16、17)、Knex 0.95.13、PG 8.7.1。 - Kleioz