나는 건설 nestjs 응용 프로그램을 사용하는 typeorm 과 통신하는 postgresql.
내 테이블을 동적으로 생성되고,데이터를 삽입 또한 동적이다. 그 이유는 내가 사용하는 원 대신하여 쿼리 entities.
문제는 일부 테이블에서 데이터는 서로 관련되어 있으므로 나는 삽입할 수 없습 새로운 데이터전 삽입 쿼리가 완료되었습니다.
는지 확인하려면 어떻게 해야 하는 쿼리 실행이 있습니다. 여기에 예를 들어의 워크플로는 내가 사용합니다. 그것은 작은 데이터지만 실패하는 빅 데이터(10 000 000 항목과 이상)
export class Test {
constructor(
private readonly connection: Connection;
) {}
public async insertData(table1, table2, arr1, arr2) {
await insertInto(table1, arr1);
//I want second insertInto() to be executed after I get confirmation from database that insertInto() from above is finished
await insertInto(table2, arr2);
}
private async insertInto(table, data) {
const queryRunner = this.connection.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
const preparedData = [];
//prepare data to be inserted as raw query
//...
try {
await queryRunner.query(`INSERT IGNORE INTO "${table}" VALUES ${preparedData}`);
await queryRunner.commitTransaction();
} catch (e) {
await queryRunner.rollbackTransaction();
throw new InternalServerErrorException(e, Error while executing custom query. Rollback transaction.)
} finally {
await queryRunner.release();
}
}
}
원하는 결과가를 위한 콜백 queryRunner.query
다음과 같이 queryRunner.query('raw_sql', (err, res) => {})
그것은으로 가능한 typeorm?
감사