This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getConnection } from 'typeorm'; | |
// ... | |
@Post('remittance-with-typeorm-transaction') | |
@ApiResponse({ | |
type: RemittanceResultDto, | |
}) | |
async makeRemittanceWithTypeOrmTransaction(@Body() remittanceDto: RemittanceDto) { | |
return await getConnection().transaction(transactionManager => { | |
return this.appService.makeRemittanceWithTypeOrmV1(transactionManager, remittanceDto.userIdFrom, remittanceDto.userIdTo, remittanceDto.sum, remittanceDto.withError); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
@Post('remittance-with-typeorm-transaction') | |
@ApiResponse({ | |
type: RemittanceResultDto, | |
}) | |
async makeRemittanceWithTypeOrmTransaction(@Body() remittanceDto: RemittanceDto) { | |
return await this.connection.transaction(transactionManager => { | |
return this.appService.makeRemittanceWithTypeOrmV1(transactionManager, remittanceDto.userIdFrom, remittanceDto.userIdTo, remittanceDto.sum, remittanceDto.withError); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transaction() | |
save(user: User, @TransactionManager() transactionManager: EntityManager) { | |
return transactionManager.save(User, user); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getConnection } from 'typeorm'; | |
await getConnection().transaction(async transactionalEntityManager => { | |
await transactionalEntityManager.save(users); | |
await transactionalEntityManager.save(photos); | |
// ... | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
async makeRemittance(fromId: number, toId: number, sum: number, withError = false, transaction = true): Promise<RemittanceResultDto> { | |
const fromUser = await this.userRepository.findOne(fromId, { transaction }); | |
const toUser = await this.userRepository.findOne(toId, { transaction }); | |
if (fromUser === undefined) { | |
throw new Error(NOT_FOUND_USER_WITH_ID(fromId)); | |
} | |
if (toUser === undefined) { | |
throw new Error(NOT_FOUND_USER_WITH_ID(toId)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
START TRANSACTION | |
// ... | |
SELECT "Purse"."id" AS "Purse_id", "Purse"."balance" AS "Purse_balance", "Purse"."userId" AS "Purse_userId" | |
FROM "purse" "Purse" | |
WHERE "Purse"."id" IN ($1) | |
UPDATE "purse" | |
SET "balance" = $2 | |
WHERE "id" IN ($1) | |
ROLLBACK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
START TRANSACTION | |
// ... | |
SELECT "Purse"."id" AS "Purse_id", "Purse"."balance" AS "Purse_balance", "Purse"."userId" AS "Purse_userId" | |
FROM "purse" "Purse" | |
WHERE "Purse"."id" IN ($1) | |
UPDATE "purse" | |
SET "balance" = $2 | |
WHERE "id" IN ($1) | |
SELECT "Purse"."id" AS "Purse_id", "Purse"."balance" AS "Purse_balance", "Purse"."userId" AS "Purse_userId" | |
FROM "purse" "Purse" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
SELECT "User"."id" AS "User_id", "User"."name" AS "User_name", "User"."defaultPurseId" AS "User_defaultPurseId" | |
FROM "user" "User" | |
WHERE "User"."id" IN ($1) | |
START TRANSACTION | |
UPDATE "purse" | |
SET "balance" = $2 | |
WHERE "id" IN ($1) | |
COMMIT | |
SELECT "Purse"."id" AS "Purse_id", "Purse"."balance" AS "Purse_balance", "Purse"."userId" AS "Purse_userId" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef Creator<TDataType> = void Function(BackendArgument<TDataType> argument); | |
void createFirstBackend(BackendArgument<void> argument) { | |
FirstBackend(argument.toFrontend); | |
} | |
@protected | |
Future<void> initBackend<TDataType extends Object>(Creator<TDataType> creator, {TDataType data, ErrorHandler errorHandler}) async { | |
/// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Events { | |
increment, | |
decrement, | |
} | |
class FirstState with ChangeNotifier, Frontend<Events> { | |
int counter = 0; | |
void increment([int diff = 1]) { | |
send(Events.increment, diff); |