我正在尝试使用来自express with node的promise-mysql模块连接到数据库,我的文件如下。从控制台,我可以毫无问题地连接到mysql,就像使用phpmyAdmin或Workbench
当我收到错误消息
TypeError:pool.getConnection不是函数
Keys.ts
export default {
database : {
host : 'localhost',
user: 'root',
password: '124563',
database: 'ng_db'
}
}
database.ts
import mysql from 'promise-mysql';
import keys from './keys';
const pool = mysql.createPool(keys.database);
pool.getConnection()
.then(connection => {
pool.releaseConnection(connection);
console.log('DB is Connected');
});
export default pool;
gameController.ts
import { Request,Response } from 'express';
import pool from '../database';
class GameController {
public index (req: Request, res: Response) {
pool.query('DESCRIBE game');
res.json('game')
}
}
export const gameController = new GameController();
export default gameController;