gpt4 book ai didi

javascript - 错误: Property 'getConnection' does not exist on type 'Bluebird'

转载 作者:行者123 更新时间:2023-11-29 09:39:38 35 4
gpt4 key购买 nike

我需要帮助,尝试使用 .createPool 连接到 MySQL 数据库时告诉我此错误:

类型“Bluebird”上不存在属性“getConnection”。您忘记使用“等待”了吗?

几个月前我尝试过,一切都很顺利:/。我认为在promise-mysql的第3版中发生了一些变化。我正在使用 typescript ,并尝试执行休息 API

使用“promise-mysql”:“^4.0.4”,ES6,

`import mysql from 'promise-mysql';

import keys from './keys';

const pool = mysql.createPool(keys.database);

pool.getConnection()
.then((connection: any) => {
pool.releaseConnection(connection);
console.log('DB is connected');
});
export default pool;`

最佳答案

`enter code here`**Importa desde 'mysql' proque soporta las librerias de getConnection()**

import mysql from 'mysql';`enter code here`
import keys from './keys';

const pool = mysql.createPool(keys.database);


pool.getConnection((err, connection) => {
if (err) throw err; connection.release();
console.log('DB is connected');

});


**Tu contolador quedaria asi:**

import{Request, Response} from 'express';
import pool from '../database';

class GamesController{
public index(req: Request, res: Response){
pool.query('DESCRIBE games');
res.json('games');
}
}
const gamesController = new GamesController();
export default gamesController;

关于javascript - 错误: Property 'getConnection' does not exist on type 'Bluebird<Pool>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56895626/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com