nest
nest copied to clipboard
sample(34-request-scope-datasource): request-scoped datasource
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
- [ ] Tests for the changes have been added (for bug fixes / features)
- [x] Docs have been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
- [ ] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] CI related changes
- [x] Other... Please describe: sample
What is the current behavior?
Issue Number: N/A
What is the new behavior?
This sample demonstrates how to implement a request-scoped DataSource in NestJS. The new behavior involves dynamically selecting the appropriate DataSource based on the user ID provided in the request headers. Specifically:
- On application startup, a main database connection is established to store client-specific database configurations.
- For each incoming request, a client-id header is extracted, and the corresponding database connection information is retrieved from the main database.
- A DataSource specific to the client is instantiated and used to handle the request, ensuring that the correct client-specific database is queried for each operation.
Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
Other information
Pull Request Test Coverage Report for Build 767667bf-9114-4476-b3e0-48ab56b3f640
Details
- 0 of 0 changed or added relevant lines in 0 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage remained the same at 92.124%
| Totals | |
|---|---|
| Change from base Build 94cfa8c0-2cff-488c-b4b7-6f54fde1b9de: | 0.0% |
| Covered Lines: | 6737 |
| Relevant Lines: | 7313 |
💛 - Coveralls
Hi @micalevisk, hope you're doing well ! I did the requested minor changes, is that ok for you? :)
Thanks for your contribution @AlexandreDecollas! However, there's already a lot of examples in this repository and maintaining them becomes a bit of a hassle. If you could create a dedicated repository for this example and link in this PR, that would be great! Thanks for understanding!