@c10k/tx-manager
v0.0.2
Published
NodeJS MySQL TxManager and MapperFactory
Downloads
1
Maintainers
Readme
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:
- tests/resources/mapper/TestMapper.xml
- tests/src/services/TestService.js
- Contains the concepts of Dao, Mapper, and Service.
- 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`);
});
});