I am looking to perform a bulk insert/update using TypeORM
The Test
entity is defined below:
export class Test {
@PrimaryColumn('integer')
id: number;
@Column('varchar', { length: 255 })
testName: string;
}
I have the following objects that I want to insert in batch:
const test1 = new Test();
script.id = 1;
script.testName = 't1';
const test2 = new Test();
test2.id = 2;
test2.testName = 't2';
const test3 = new Test();
test3.id = 3;
test3.testName = 't3';
const tests = [test1, test2, test3];
However, when I attempt to save them together like this:
const testRepository = dataSource.getRepository(Test);
await testRepository.save(tests);
It doesn't work as expected. Strangely enough, testRepository.save(test1);
works fine.
Can you guide me on how to perform a batch insert, especially when dealing with thousands of rows?