这是我的代码:
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('/',){
res.send('DB Is Connected');
});
module.exports = router;
}
通过邮递员,我运行以下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')
并在Postman中加入以下内容,我进入nodemon:
GET /expressroutename/email 200 45.116 ms - 15
[ 'test@email.com',1 ]
[ 'test1@email.com',1 ]
{
getWarnings: [Function: getWarnings],toArray: [Function: toArray]
我认为这是一个语法错误,但是我已经通过文档多次输入了它,但似乎不起作用。请帮忙。
谢谢