Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误:属性';getConnection';不存在于类型';蓝鸟<;游泳池>';_Javascript_Mysql_Ecmascript 6 - Fatal编程技术网

Javascript 错误:属性';getConnection';不存在于类型';蓝鸟<;游泳池>';

Javascript 错误:属性';getConnection';不存在于类型';蓝鸟<;游泳池>';,javascript,mysql,ecmascript-6,Javascript,Mysql,Ecmascript 6,我需要帮助,正在尝试使用与MySQL数据库建立连接。createPool告诉我此错误: 类型“Bluebird”上不存在属性“getConnection”。您是否忘记使用“等待”? 几个月前我试过了,一切都很顺利:/。 我认为promise mysql的第3版有一些变化。 我正在使用typescript并尝试执行RESTAPI 使用“承诺mysql”:“^4.0.4”、ES6、 请尝试等待池创建完成: pool.then((r: any) => r.getConnection().then

我需要帮助,正在尝试使用与MySQL数据库建立连接。createPool告诉我此错误:

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

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

使用“承诺mysql”:“^4.0.4”、ES6、


请尝试等待池创建完成:

pool.then((r: any) => r.getConnection().then((connection: any) => {
  pool.releaseConnection(connection);
  console.log("DB is connected");
});

请尝试等待池创建完成:

pool.then((r: any) => r.getConnection().then((connection: any) => {
  pool.releaseConnection(connection);
  console.log("DB is connected");
});
解决方案:

import mysql from 'mysql';

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');
})
export default pool;
解决方案:

import mysql from 'mysql';

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');
})
export default pool;
我的解决方案

import mysql from 'promise-mysql';

import keys from './keys';

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

pool.then((r: any) => r.getConnection().then((connection:any)=>{
    r.releaseConnection(connection);
    console.log('Conexion exitosa.')
}));

export default pool;
我的解决方案

import mysql from 'promise-mysql';

import keys from './keys';

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

pool.then((r: any) => r.getConnection().then((connection:any)=>{
    r.releaseConnection(connection);
    console.log('Conexion exitosa.')
}));

export default pool;

你可以试试这个版本
npm安装承诺-mysql@3.3.1

您可以尝试使用此版本
`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;

npm安装承诺-mysql@3.3.1

您必须将promise mysql的版本更改为3.3.1,就是这样。

您必须将promise mysql的版本更改为3.3.1,就是这样。

安装promise mysql的最新版本:

`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;
npm i promise-mysql@3.3.1

安装Promise MySql的最新版本:

npm i promise-mysql@3.3.1

一些词解释你的解决方案会使它更有用。一些词解释你的解决方案会使它更有用。你能解释一下你的答案为什么有效吗?所以问题是池中不存在getConnection。他怎么能修好它?然后答案是:'您应该执行'pool.getConnection'。但他只是说游泳池里根本就没有@RodnalCode pool.query也不存在:类型“Bluebird”上不存在属性“query”。您能解释一下为什么您的答案有效吗?所以问题是池中不存在getConnection。他怎么能修好它?然后答案是:'您应该执行'pool.getConnection'。但他只是说游泳池里根本就没有@RodnalCode pool.query也不存在:类型“Bluebird”上不存在属性“query”,然后:类型“Bluebird”上不存在属性“releaseConnection”,然后:类型“Bluebird”上不存在属性“releaseConnection”