📅  最后修改于: 2022-03-11 14:59:58.284000             🧑  作者: Mango
// remember to use a transaction as you are not sure whether the user is
// already present in DB or not (and you might end up creating the user -
// a write operation on DB)
models.sequelize.transaction(function(t) {
return models.users.findOrCreate({
where: {
userId: profile.userId,
name: profile.name
},
transaction: t
})
.spread(function(userResult, created){
// userResult is the user instance
if (created) {
// created will be true if a new user was created
}
});
});