Skip to content

hypernova1/typeorm-parallel-transaction-manager

Repository files navigation

TypeORM Parallel Transaction Manager

This is a library that can obtain multiple connections and execute queries in parallel.

How to use

// Initialize TypeORM DataSource
const dataSource = new DataSource({...});

// Initialize an instance of ParallelTransactionManager
const parallelTransactionManager = new ParallelTransactionManager(dataSource);

// Initialize an array of items to process (e.g., [1, 2, 3, 4])
const foos: Foo[] = [...];

// Run transactions in parallel and collect the results
const bars = await parallelTransactionManager.run(foos, async (foo: Foo, queryRunner: QueryRunner) => {
    // Perform tasks on each item (e.g., create a new Bar instance and save to the database)
    const bar = new Bar(foo);
    await queryRunner.manager.save(Bar, bar);
    return bar; // Return the result
});

// Output the results (or further process them)
console.log(bars);

About

Library that can obtain multiple connections and execute queries in parallel.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published