0
I have a connection with two databases, with different servers, and would like to perform the Join between the tables of the two banks, using querybuilder. Would someone please help me?
import databaseConfig from "../../config/database";
import { Sequelize } from 'sequelize';
class UsersController {
async index(req, res) {
const env = process.env.NODE_ENV || 'development';
const config = databaseConfig[env];
const db_one = config.databases['db_one']; // Primeira Conexão
const db_two = config.databases['db_two']; // Segunda Conexão
const bases = [new Sequelize(db_one ),new Sequelize(db_two )];
let query = 'SELECT * FROM db1.users as u LEFT JOIN db2.group_users as gu ON u.id_group = gu.id';
for (let i in bases ) {
const result = await bases[i].query(query,{ raw: true });
console.log(result);
}
}
}