我有一个功能来检索用户的个人资料。
app.get('/api/user/profile', function (request, response) { // Create the default error container var error = new Error(); var User = db.User; User.find({ where: { emailAddress: request.user.username} }).then(function(user) { if(!user) { error.status = 500; error.message = "ERROR_INVALID_USER"; error.code = 301; return next(error); } // Build the profile from the user object profile = { "firstName": user.firstName, "lastName": user.lastName, "emailAddress": user.emailAddress } response.status(200).send(profile); }); });
当调用“find”函数时,它会在启动服务器的控制台上显示 select 语句。
Executing (default): SELECT `id`, `firstName`, `lastName`, `emailAddress`, `password`, `passwordRecoveryToken`, `passwordRecoveryTokenExpire`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`emailAddress` = 'johndoe@doe.com' LIMIT 1;
有没有办法让它不显示?我在某个配置文件中设置的一些标志?
创建 Sequelize 对象时,传递false给logging参数:
false
logging
var sequelize = new Sequelize('database', 'username', 'password', { // disable logging; default: console.log logging: false });
有关更多选项,请查看文档。