@c10k/tx-manager

0.0.2 • Public • Published

tx-manager

Provides CRUD development experience similar to Spring-Boot + MyBatis using mysql2 and mybatis-mapper.

npm install @c10k/tx-manager

Declaration and Usage of Mapper.xml

Refer to the following files:

  1. tests/resources/mapper/TestMapper.xml
  2. tests/src/services/TestService.js
    • Contains the concepts of Dao, Mapper, and Service.
  3. tests/src/config/database.js
    • Similar to Bean objects in Spring-Boot

Using MySQL Transactions

The following code demonstrates how to start a transaction, and use the same transaction in nested callbacks, satisfying most development scenarios.

const uuid1 = uuidv4();
const uuid2 = uuidv4();
await txManager.runTransaction(async (_, connectionId1) => {
    const id1 = await testService.save(uuid1);

    await txManager.runTransaction(async (_, connectionId2) => {
        const id2 = await testService.save(uuid2);

        expect(connectionId1).toBe(connectionId2);

        const {id: connectionId3} = txManager.getCurrentContext();

        expect(connectionId1).toBe(connectionId3);

        throw new Error(`rollback by error`);
    });
});

Package Sidebar

Install

npm i @c10k/tx-manager

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

22.3 kB

Total Files

12

Last publish

Collaborators

  • qyvlik