typeorm icon indicating copy to clipboard operation
typeorm copied to clipboard

TypeORM module save my data in wrong database, is this bug?

Open Kayxue opened this issue 3 years ago • 1 comments

I hope my data can save in bot database image

And My PostgreSQLConnection.ts:

import {DataSource} from "typeorm";
import DynamicVoiceChannel from "./Entities/Bot/dvcEntity";

const dataSource=new DataSource({
    type:"postgres",
    host:"localhost",
    port:5432,
    database:"bot", 
    username:"postgres",
    password:"",
    entities:[DynamicVoiceChannel],
    synchronize:true
})

export default dataSource

index.ts:

import PostgreConnection from "./PostgreSQLConnection";
import MongoConnection from "./MongoConnection"
import DynamicVoiceChannel from "./Entities/Bot/dvcEntity";
(async () => {
    const mongo=await MongoConnection.initialize()
    const Postgre=await PostgreConnection.initialize()

    const mongoCol=mongo.getMongoRepository(DynamicVoiceChannel);
    const datas=await (await mongoCol.find()).map(e => {
        delete e._id
        return e
    })
    const PostgreCol=Postgre.getRepository(DynamicVoiceChannel)
    for(const d of datas){
        await PostgreCol.insert(d);
    }
    console.log("End")
})()

And it save my data here image So...... is this bug? Or what I forgot to do?

Kayxue avatar May 09 '22 07:05 Kayxue

Find a solution? Having the same issue. Always reads/writes from the postgres db even though I explicitly declare the custom.

beauxjames avatar May 23 '24 02:05 beauxjames