如果我从 Ruby on Rails 切换到 Sequelize,我会使用哪些等效代码。
如果我想要使用同构 JavaScript,我可能会想要使用 Node.js 的 ORM...
在我投入太多时间在一个方面与另一个方面之前,有什么建议吗?
我看过 Sequelize、ORM NPM、Active Record Npm,它们看起来都不错,但我不确定哪个效果最好。如果有人可以向我展示他们的 Node 等效 ORM 的一些翻译,我将能够快速实现它并了解很多有关 ORM 工作原理的知识。谢谢。
如果有人可以提供一个简短的指南,告诉我如何将这个 Ruby on Rails 代码转换为 Sequelize JS 或 Bookshelf JS 的等效位,我可以决定哪个看起来最方便。
def show
@pet = Pet.find_by(id: params[:id])
if @pet
render json: @pet
else
render status: 400, nothing: true
end
end
def update
@pet = Pet.find_by(id: params[:id])
if @pet.update(pet_params)
render json: @pet
else
render status: 400, nothing: true
end
end
private
def pet_params
params.require(:pet).permit(:name, :species, :author_id)
end
这会让我的生活变得更加轻松,谢谢。
最佳答案
我相信sequelize拥有最好的文档,正如您可能在其他答案中看到的那样。
app.get("Projects/:id", function (res,req){
var particularProj=Project.findById(params.id).then(function(project) {
// project will be an instance of Project and stores the content of the table entry with id 123. if such an entry is not defined you will get null
res.render("show.ejs", {proj: particularProj}
});
});
类似于 Ruby on Rails Active Record 中的以下内容:
def show
proj=Project.find(params[:id]);
@proj=proj
end
关于javascript - Ruby On Rails 到 Node.js 中的 Sequelize(或其他 ORM)的翻译是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30424761/