-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: use NestJS design patterns #37
Merged
Merged
Conversation
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
+ this fixes the necessity to cd to src/db to apply migrations and allows executing the script from anywhere
Move things around to a NestJS-like resource based structure, based on plural and not singular
this is more inline with nestjs standards
yamcodes
changed the title
feat: drizzle + postgress + patch
refactor: borrow NestJS design patterns
Sep 25, 2023
yamcodes
changed the title
refactor: borrow NestJS design patterns
refactor: use NestJS design patterns
Sep 25, 2023
Closed
This was referenced Oct 16, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Applies a patch to @Hajbo's drizzle + postgres setup.
Changes
The biggest change here is refactoring the code to match NestJS principles as much as possible, while still taking the ElysiaJS docs seriously.
Since this is balance is subtle and groundbreaking* (see note below), I left comments in the code explaining the considerations. Please review and feel free to take them out before merge or in a dedicated PR.
The best way to review this PR is to pull it into your IDE, run the code, and play around with the file structure, maybe try to add a feature or two to the users service.
See commits for full details
src
Operations like
seed
andmigrations
should not be placed insrc
as they are not a part of the source-code. See other RealWorld apps with a similar design: 1 2src/database.providers.ts
(reference for the filename)migrate.ts
work from anywhere, including project rootGroundbreaking
This balance (between NestJS best practices and ElysiaJS best practices) is groundbreaking since it is not the same as projects that try to mimic NestJS in Express are different. Elysia strongly encourages method-chaining which is not a common Express/Fastify practice.
Follow-up Considerations
./db
to./drizzle
to avoid confusion with./src/database.providers.ts
. I didn't do it here because I'm not a big fan of vendor-locking by naming files by technology.*.module.ts
,*.entity.ts
, etc. Let's carefully add them as needed, but let's try to avoid put everything in*.schema.ts
just because we don't know where else to put it. See references for theusers
folder in other RealWorld apps: 1 - busy example 2 - lean example. Naturally, this will also depend on the way we infer types and schemas (usingdrizzle-typebox
and the likes)