我是Knex的新手,我尝试了一些交易。当我发送电子邮件地址到用户表时,它发送的像{"email":" [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) "}
,我迷路了,有人能帮助我吗?
app.post('/register', (req, res) =>{
const {email, name, password } = req.body;
const hash = bcrypt.hashSync(password);
db.transaction(trx =>{
trx.insert ({
has: hash,
email: email
})
.into('login')
.returning('email')
.then (loginEmail => {
return trx('users')
.returning('*')
.insert({
email:loginEmail[0],
name: name,
joined: new Date()
}).then(user =>{
res.json(user[0]);
})
})
.then(trx.commit)
.catch(trx.rollback)`
})
})
字符串
1条答案
按热度按时间hmtdttj41#
在第二个插入中插入了
loginEmail[0]
。你应该插入的是
loginEmail[0].email
,如果不是,你在技术上插入的对象看起来像{ email: ' [[email protected]](https://stackoverflow.com/cdn-cgi/l/email-protection) ' }
字符串
我冒昧地添加了一些格式,并替换了dbResponse的变量,使其稍微清晰一些。