我需要帮助,尝试使用.createPool建立与MySQL数据库的连接会告诉我此错误:
类型“ Bluebird”上不存在属性“ getConnection”。您忘了使用“等待”吗?
几个月前,我尝试了一下,一切顺利:/。
我认为在promise-mysql的版本3中有一些更改。
我正在使用打字稿,我尝试执行rest 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 - 错误:类型“Bluebird <Pool>”上不存在属性“getConnection”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56895626/