gpt4 book ai didi

javascript - 使用附加数据将函数传递给 sails.js

转载 作者:行者123 更新时间:2023-11-30 17:26:59 24 4
gpt4 key购买 nike

我想检查一个用户是否已经存在于数据库中。如果不是,我想添加它。我正在使用 sails.js v0.10.0-rc7。

Item.findOne(id).then(function(obj){
how can I access id??? so that if obj is empty I can create it?
}, function(error){
sails.log.warn("error:"+error);
});

最佳答案

您可以像这样使用 findorCreate 函数:

Item.findOrCreate(id,{id: '213',name:'foouser'}).exec(function(err,resitem){
if(err){
sails.log.warn("error:"+error);
}else{
sails.log(resitem);
}
});

参见:http://beta.sailsjs.org/#/documentation/reference/Models/Model-Methods/findOrCreate.html

关于javascript - 使用附加数据将函数传递给 sails.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24055267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com