mysql 后端使用 node-orm2 的数据库更新问题
Database update issue using node-orm2 for mysql backend
问题:
我正在开发一个 Android 应用程序,它使用 mysql 后端的节点 orm 与 nodejs REST 服务器交互。在我的服务器上,我有一个基于电子邮件验证来验证用户身份的功能。验证成功后,节点 orm 获取用户对象,更改已验证的列值并将其保存回来。
但是,更改不会在执行后反映在数据库中。仅当我们再次 运行 相同的代码时,它才会反映在数据库中
代码
exports.activateEmail = function(email, callback) {
log.info('In verifyEmailDao.js, activateEmail module');
var db = connectionObj.getConnection();
var Candidate = db.models.jobseeker_id;
Candidate.find({email : email}, function(err,candidate){
if(err){
log.info('cannot find account with email to activate', email);
callback(false, null);
}
else {
candidate[0].verified = true;
log.info('candidate email now activated.! status is', candidate[0].verified);
candidate[0].save(function(error){
log.info('Email verified any errors?', error);
callback(true, candidate[0].id);
});
}
});
}
编辑 1:
jobseeker_id.js(节点模型)
var orm = require('orm');
module.exports = function(db){
console.log('coming inside candidateId.js');
var JobSeekerId = db.define('jobseeker_id', {
id : {type:'serial' , key:true},
first_name : String,
last_name : String,
email : String,
password : String,
verified : Boolean
},{
validations : {
email : orm.enforce.unique("Already registered")
}
});
}
服务器日志:
{"name":"test-app" "msg":"In verifyEmailDao.js, activateEmail module"}
{"name":"test-app","msg":"candidate email now activated.! status is true"}
{"name":"test-app","msg":"Email verified any errors? null"}
{"name":"test-app","msg":"Email sucessfully activated. Now deleting the entry from verify email link table for candidate id 30}
{"name":"test-app","msg":"In verifyEmailDao.js, deleteRandomLink module"}
{"name":"test-app","msg":"error is---> null"}
{"name":"test-app","msg":"Entry deleted from verify email table as email is activated"}
我第二次执行代码时,log中不会没有任何变化,但会反映db中的变化!
经过 2 天的苦战,我终于通过向数据库配置文件添加语句 db.settings.set('instance.cache', false)
解决了这个问题。虽然我不太清楚如何通过将缓存设置为 false 来解决数据库更新问题,但这确实有效!
问题: 我正在开发一个 Android 应用程序,它使用 mysql 后端的节点 orm 与 nodejs REST 服务器交互。在我的服务器上,我有一个基于电子邮件验证来验证用户身份的功能。验证成功后,节点 orm 获取用户对象,更改已验证的列值并将其保存回来。 但是,更改不会在执行后反映在数据库中。仅当我们再次 运行 相同的代码时,它才会反映在数据库中
代码
exports.activateEmail = function(email, callback) {
log.info('In verifyEmailDao.js, activateEmail module');
var db = connectionObj.getConnection();
var Candidate = db.models.jobseeker_id;
Candidate.find({email : email}, function(err,candidate){
if(err){
log.info('cannot find account with email to activate', email);
callback(false, null);
}
else {
candidate[0].verified = true;
log.info('candidate email now activated.! status is', candidate[0].verified);
candidate[0].save(function(error){
log.info('Email verified any errors?', error);
callback(true, candidate[0].id);
});
}
});
}
编辑 1:
jobseeker_id.js(节点模型)
var orm = require('orm');
module.exports = function(db){
console.log('coming inside candidateId.js');
var JobSeekerId = db.define('jobseeker_id', {
id : {type:'serial' , key:true},
first_name : String,
last_name : String,
email : String,
password : String,
verified : Boolean
},{
validations : {
email : orm.enforce.unique("Already registered")
}
});
}
服务器日志:
{"name":"test-app" "msg":"In verifyEmailDao.js, activateEmail module"}
{"name":"test-app","msg":"candidate email now activated.! status is true"}
{"name":"test-app","msg":"Email verified any errors? null"}
{"name":"test-app","msg":"Email sucessfully activated. Now deleting the entry from verify email link table for candidate id 30}
{"name":"test-app","msg":"In verifyEmailDao.js, deleteRandomLink module"}
{"name":"test-app","msg":"error is---> null"}
{"name":"test-app","msg":"Entry deleted from verify email table as email is activated"}
我第二次执行代码时,log中不会没有任何变化,但会反映db中的变化!
经过 2 天的苦战,我终于通过向数据库配置文件添加语句 db.settings.set('instance.cache', false)
解决了这个问题。虽然我不太清楚如何通过将缓存设置为 false 来解决数据库更新问题,但这确实有效!