我正在尝试使用 express with node 中的 promise-mysql 模块连接到数据库,我的文件如下。从控制台我可以毫无问题地连接到 mysql,就像使用 phpmyAdmin 或 Workbench
执行时我收到错误
类型错误:pool.getConnection 不是函数
键.ts
export default {
database : {
host : 'localhost',
user: 'root',
password: '124563',
database: 'ng_db'
}
}
数据库.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;
游戏控制器.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;
问题是
promise
您拥有的版本,我认为您正在做 Fazt 教程(Angular Mysql CRUD 教程,REST API 节点和 Typescript)来解决它,您只需在终端中执行命令:我遇到了完全相同的问题,它对我有用。问候。