【发布时间】:2020-03-20 00:48:26
【问题描述】:
这是我的代码:
var express = require('express');
var router = express.Router();
var mysqlx = require('@mysql/xdevapi');
router.use(`/:email`, function (req, res, next){
mysqlx.getSession( {
user: 'username',
password: 'password',
host: 'localhost',
port: '33060' } )
// .then(session => {
// console.log(session.inspect());
// })
.then(function (session) {
var db = session.getSchema('nms2019local');
var opsTable = db.getTable('operators');
return opsTable
.select (['email', 'admin'])
.where('email like :email')
.bind('email',':email')
.execute (function (row) {
console.log(row);
});
})
.then(function (myResult){
console.log(myResult);
})
.catch(function (err){
console.log(err);
})
next()
});
router.use('/', function (req, res,){
res.send('DB Is Connected');
});
module.exports = router;
}
我通过邮递员运行以下 GET 命令:
get /expressroutename/email/test@email.com 我在 nodemon 中得到以下信息:
GET /expressroutename/email/test@email.com 200 36.096 ms - 15
{
getWarnings: [Function: getWarnings],
getWarningsCount: [Function: getWarningsCount],
fetchAll: [Function: fetchAll],
fetchOne: [Function: fetchOne],
getColumns: [Function: getColumns],
getResults: [Function: getResults],
nextResult: [Function: nextResult],
toArray: [Function: toArray]
}
当我列出 .where 命令时
//.where('email like :email')
并在我在 nodemon 中得到的 Postman 中输入以下内容:
GET /expressroutename/email 200 45.116 ms - 15
[ 'test@email.com', 1 ]
[ 'test1@email.com', 1 ]
{
getWarnings: [Function: getWarnings],
getWarningsCount: [Function: getWarningsCount],
fetchAll: [Function: fetchAll],
fetchOne: [Function: fetchOne],
getColumns: [Function: getColumns],
getResults: [Function: getResults],
nextResult: [Function: nextResult],
toArray: [Function: toArray]
我认为这是一个语法错误,但我已经通过文档多次输入它,但它似乎不起作用。请帮忙。
谢谢
【问题讨论】:
标签: mysql node.js express mysql-8.0