npm

@rosen-bridge/atomic-typeorm-create-query-runner
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

@rosen-bridge/atomic-typeorm-create-query-runner

Table of contents

Introduction

By default, typeorm doesn't handle parallel transactions. If you run two transactions simultaneously and your database doesn't support it (e.g. if you use sqlite), you will get errors.

Installation

npm:

npm i @rosen-bridge/atomic-typeorm-create-query-runner

yarn:

yarn add @rosen-bridge/atomic-typeorm-create-query-runner

Usage

import createAtomicQueryRunner from '@rosen-bridge/atomic-typeorm-create-query-runner';

const foo = () => {
  // const queryRunner = dataSource.createQueryRunner();
  const queryRunner = createAtomicQueryRunner(dataSource);

  await queryRunner.connect();
  await queryRunner.startTransaction();

  try {
    await applyAtomicQuery();
    await queryRunner.commitTransaction();
  } catch {
    await queryRunner.rollbackTransaction();
  } finally {
    await queryRunner.release();
  }
};

// You can now call the transactions simultaneously without getting errors
foo();
foo();

As you can see, no big changes required to use the package.

Readme

Keywords

Package Sidebar

Install

npm i @rosen-bridge/atomic-typeorm-create-query-runner

Weekly Downloads

2

Version

0.0.1

License

GPL-3.0

Unpacked Size

173 kB

Total Files

25

Last publish

Collaborators

  • vorujack
  • zargarzadehm