मैं निर्माण कर रहा हूँ एक nestjs आवेदन का उपयोग करता है कि typeorm के साथ संवाद करने postgres.
मेरी मेज गतिशील बनाया जाता है, और डेटा डाला जाता है, यह भी गतिशील रूप से । यही कारण है कि मैं का उपयोग कच्चे क्वेरी के बजाय संस्थाओं.
समस्या यह है कि कुछ डेटा तालिकाओं से संबंधित हैं और मैं नहीं कर सकते हैं, नए डेटा सम्मिलित है, जब तक पिछला सम्मिलित क्वेरी समाप्त हो गया है.
कैसे मैं अगर जाँच क्वेरी निष्पादन समाप्त हो गया? यहाँ है एक उदाहरण के कार्यप्रवाह है कि मैं का उपयोग करें । यह काम करता है के साथ छोटे डेटा में विफल रहता है, लेकिन बड़ा डेटा के साथ (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?
धन्यवाद