This file contains hidden or 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 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(const MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| const MyApp({super.key}); | |
| @override |
This file contains hidden or 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
| void main(List<String> arguments, dynamic message) { | |
| print('GITHUB: Arguments from your isolate: $arguments'); | |
| print('GITHUB: Message from your isolate: $message'); | |
| // V3 | |
| } |
This file contains hidden or 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 hidden or 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-transaction-and-fee') | |
| @ApiResponse({ | |
| type: RemittanceResultDto, | |
| }) | |
| async makeRemittanceWithTransactionAndFee(@Body() remittanceDto: RemittanceDto) { | |
| return this.connection.transaction(async manager => { | |
| const transactionAppService = this.appService.withTransaction(manager); // <-- this is interesting new thing | |
| const result = await transactionAppService.makeRemittance(remittanceDto.userIdFrom, remittanceDto.userIdTo, remittanceDto.sum, remittanceDto.withError); | |
| result.fromBalance -= 1; // <-- transfer fee |
This file contains hidden or 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 hidden or 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 hidden or 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
| @Injectable() | |
| export class AppService extends TransactionFor<AppService> /* <-- step 1 */ { | |
| constructor( | |
| @InjectRepository(User) | |
| private readonly userRepository: Repository<User>, | |
| @InjectRepository(Purse) | |
| private readonly purseRepository: Repository<Purse>, | |
| private readonly appServiceV2: AppServiceV2, | |
| moduleRef: ModuleRef, // <-- step 2 | |
| ) { |
This file contains hidden or 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 hidden or 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-transaction') | |
| @ApiResponse({ | |
| type: RemittanceResultDto, | |
| }) | |
| async makeRemittanceWithTransaction(@Body() remittanceDto: RemittanceDto) { | |
| return await this.connection.transaction(transactionManager => { | |
| return this.appService.withTransaction(transactionManager)/* <-- this is interesting new thing*/.makeRemittance(remittanceDto.userIdFrom, remittanceDto.userIdTo, remittanceDto.sum, remittanceDto.withError); | |
| }); | |
| } |
This file contains hidden or 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
| @Controller() | |
| @ApiTags('app') | |
| export class AppController { | |
| constructor( | |
| private readonly appService: AppService, | |
| private readonly connection: Connection, // <-- use this | |
| ) { | |
| } | |
| // ... | |
| } |
NewerOlder