{"id":23397533,"url":"https://github.com/leocode/nest-tx","last_synced_at":"2025-04-08T18:21:21.679Z","repository":{"id":38937364,"uuid":"315466606","full_name":"leocode/nest-tx","owner":"leocode","description":"Database transaction module for NestJS","archived":false,"fork":false,"pushed_at":"2022-10-07T08:02:15.000Z","size":410,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-30T03:39:40.667Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leocode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-23T23:33:02.000Z","updated_at":"2022-09-27T10:02:37.000Z","dependencies_parsed_at":"2022-09-13T02:41:29.723Z","dependency_job_id":null,"html_url":"https://github.com/leocode/nest-tx","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocode%2Fnest-tx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocode%2Fnest-tx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocode%2Fnest-tx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leocode%2Fnest-tx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leocode","download_url":"https://codeload.github.com/leocode/nest-tx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247898521,"owners_count":21014722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-22T08:19:09.483Z","updated_at":"2025-04-08T18:21:21.618Z","avatar_url":"https://github.com/leocode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nest-tx - database transaction manager for NestJS\n\n[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)\n\n## Motivation\n\nTransaction management is usually done in application services, which should not have knowledge of implementation\ndetails\nlike DB engine or DB access library (like TypeORM). This way you can change the underlying DB technology without\nmodifying\nbusiness logic. `@leocode/nest-tx-core` provides an abstract way of managing transactions - it is not tied to any\nparticular database, driver or ORM. It can be used with many libraries and drivers by using adapters (\nlike `@leocode/nest-tx-typeorm`).\n\n## Currently supported ORMs/query builders/drivers:\n\n- Knex\n- TypeORM\n\n## Installation\n\n`@leocode/nest-tx-core` must always be installed:\n\n```\nyarn add @leocode/nest-tx-core\n```\n\nThen you can install particular adapters (and its peer dependencies) for your application, for example:\n\n```\nyarn add @leocode/nest-tx-typeorm\n```\n\n## Usage\n\nFirst, you need to register an adapter:\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { TypeORMTransactionManagerModule } from '@leocode/nest-tx-typeorm';\n\n@Module({\n  imports: [\n    TypeORMTransactionManagerModule.forRoot(),\n  ],\n})\nexport class AppModule {}\n```\n\nThen you can use\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectTransactionManager, TransactionManager } from '@leocode/nest-tx-core';\nimport { getEntityManagerFromTypeORMTransaction } from '@leocode/nest-tx-typeorm';\n\n@Injectable()\nclass CatsService {\n  constructor(\n    @InjectTransactionManager() private transactionManager: TransactionManager,\n  ) {}\n\n  async save() {\n    await this.transactionManager.withTransaction(async (tx) =\u003e {\n      /**\n       * NOTE: Usually you should write code like this in a separate repository class -\n       * it's written here for the example brevity.\n       */\n      const manager = getEntityManagerFromTypeORMTransaction(tx);\n\n      await manager.query('SELECT * FROM \"table\"');\n    });\n  }\n}\n```\n\nConsult the README file in each package to see how to use it:\n\n- [knex](./packages/knex/README.md)\n- [typeorm](./packages/typeorm/README.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocode%2Fnest-tx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleocode%2Fnest-tx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleocode%2Fnest-tx/lists"}