将Ruby On Rails翻译成Node.js中的Sequelize(或其他orm)

What would be a translation of Ruby On Rails to Sequelize (or other ORMs) in Node.js?

本文关键字:Sequelize 其他 orm 中的 js On Ruby Rails 翻译 Node      更新时间:2023-09-26

如果我从Ruby on Rails切换到Sequelize,我将使用哪些等效代码?

如果我想使用同构JavaScript,我可能会使用Node.js的ORM…

在我花太多时间讨论一个和另一个之前,有什么建议吗?

我看过Sequelize, ORM NPM, Active Record NPM,它们看起来都很好,但我不确定哪个效果最好。如果有人能给我看一些他们的节点等效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