mysql pool.query 没有按预期工作
mysql pool.query doesn't work as expected
我有一个路由器发送 mysql 结果作为响应:
路由器
var pool = mysql.createPool({
connectionLimit: account.MYSQL_CONNECTION_LIMIT,
host: account.MYSQL_HOST,
database: account.MYSQL_DATABASE,
port: account.MYSQL_PORT,
user: account.MYSQL_USER_ID,
password: account.MYSQL_PASSWORD
})
router.get('/', async function (req, res) => {
res.json({
'activities': await pool.query(actQ(uid,gid))
})
})
function actQ (uid, gid) {
var query = "SELECT date_time, steps, calories, floors, distance, duration, pace FROM ACTIVITY ";
query += " WHERE user_id = " + uid;
query += " AND game_id = " + mysql.escape(gid);
return query
}
它一直运行良好,但它只是开始随机运行。我对 pool.query
的期望显然是 sql 查询的结果,但我得到的是这样的查询信息。
回应
{
"activities": {
"domain": null,
"_events": {},
"_eventsCount": 0,
"_callSite": {},
"_ended": false,
"_idleNext": null,
"_idlePrev": null,
"_idleStart": null,
"_idleTimeout": -1,
"_repeat": null,
"sql": "SELECT date_time, steps, calories, floors, distance, duration, pace FROM ACTIVITY WHERE user_id = 42741e32-b517-4655-92ca-af29815d236c AND game_id = '498b36ff-0b90-11e8-97c8-061227ce9ef2'",
"typeCast": true,
"nestTables": false,
"_resultSet": null,
"_results": [],
"_fields": [],
"_index": 0,
"_loadError": null
}
}
我增加了connectionLimit,但并没有解决这个问题。它运行得非常好,我仔细检查了 MYSQL 帐户,但它们没有任何问题。知道为什么会这样吗?
这是一个查询对象,在库中用于表示对数据库的请求。如果你在没有回调函数的情况下调用 pool.query
,你会得到它。如果您需要基于 Promise 的 API,请使用 node-mysql2,它将在您 await
查询调用时产生结果。
我有一个路由器发送 mysql 结果作为响应:
路由器
var pool = mysql.createPool({
connectionLimit: account.MYSQL_CONNECTION_LIMIT,
host: account.MYSQL_HOST,
database: account.MYSQL_DATABASE,
port: account.MYSQL_PORT,
user: account.MYSQL_USER_ID,
password: account.MYSQL_PASSWORD
})
router.get('/', async function (req, res) => {
res.json({
'activities': await pool.query(actQ(uid,gid))
})
})
function actQ (uid, gid) {
var query = "SELECT date_time, steps, calories, floors, distance, duration, pace FROM ACTIVITY ";
query += " WHERE user_id = " + uid;
query += " AND game_id = " + mysql.escape(gid);
return query
}
它一直运行良好,但它只是开始随机运行。我对 pool.query
的期望显然是 sql 查询的结果,但我得到的是这样的查询信息。
回应
{
"activities": {
"domain": null,
"_events": {},
"_eventsCount": 0,
"_callSite": {},
"_ended": false,
"_idleNext": null,
"_idlePrev": null,
"_idleStart": null,
"_idleTimeout": -1,
"_repeat": null,
"sql": "SELECT date_time, steps, calories, floors, distance, duration, pace FROM ACTIVITY WHERE user_id = 42741e32-b517-4655-92ca-af29815d236c AND game_id = '498b36ff-0b90-11e8-97c8-061227ce9ef2'",
"typeCast": true,
"nestTables": false,
"_resultSet": null,
"_results": [],
"_fields": [],
"_index": 0,
"_loadError": null
}
}
我增加了connectionLimit,但并没有解决这个问题。它运行得非常好,我仔细检查了 MYSQL 帐户,但它们没有任何问题。知道为什么会这样吗?
这是一个查询对象,在库中用于表示对数据库的请求。如果你在没有回调函数的情况下调用 pool.query
,你会得到它。如果您需要基于 Promise 的 API,请使用 node-mysql2,它将在您 await
查询调用时产生结果。