0

I'm trying to connect to multiple databases from single connection using typeORM in javascript. There's a way doing it using typescript

import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";

@Entity({ database: "secondDB" })
export class User {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    firstName: string;

    @Column()
    lastName: string;

}

I tried to replicate this in javascript like this:

const { EntitySchema } = require("typeorm");

const userSchema = {
   name: "User",
   database: "secondDB",
    columns: {
      id: { 
        primary: true, 
        type: "int", 
        generated: true 
     },
      firstName: { 
        type: "text"
     },
      lastName: { 
        type: "text"
     },

 }

 module.exports = new EntitySchema(userSchema);

This doesn't seem to switch databases, Is there an equivalent way of doing this in javascript. I'm connecting to a postgresDB

1 Answer 1

0

It's been a while since I worked with type-orm, but I know that a single connection with multiple databases at the time was only supported for MySQL and MsSQL databases.

In this document: https://orkhan.gitbook.io/typeorm/docs/multiple-connections. It states that "Using multiple databases in a single connection" "this feature is supported only in mysql and mssql databases".

link to relevant github issue

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.