Sequelize: Using Multiple Databases

前端 未结 3 518
Happy的楠姐
Happy的楠姐 2020-12-02 17:26

Do I need to create multiple instances of Sequelize if I want to use two databases? That is, two databases on the same machine.

If not, what\'s the proper way to do

3条回答
  •  无人及你
    2020-12-02 18:14

    if you are trying to associate objects in the same RDS across multiple databases, you can use schema.

    http://docs.sequelizejs.com/class/lib/model.js~Model.html#static-method-schema

    this will prepend the db name to the table name so, presumably, your queries would come out like: SELECT A.ColA, B.ColB FROM SchemaA.ATable A INNER JOIN SchemaB.BTable B ON B.BId = A.BId

提交回复
热议问题