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.
Move db related operations out of src
Operations like seed and migrations should not be placed in src as they are not a part of the source-code. See other RealWorld apps with a similar design: 12
Consider changing ./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.
We need to still add more structures to each resource, potentially *.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 the users folder in other RealWorld apps: 1 - busy example2 - lean example. Naturally, this will also depend on the way we infer types and schemas (using drizzle-typebox and the likes)
36 - we need to understand how to apply an OpenAPI schema to this structure.
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 likeseed
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)36 - we need to understand how to apply an OpenAPI schema to this structure.