Skip to content

feat: Kysely upgrade #12

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

Merged
merged 12 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM node:20-alpine AS base
ENV HUSKY=0
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
RUN corepack enable && corepack prepare pnpm@9.11.0 --activate

FROM base AS build
WORKDIR /app
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
release: PGSSLMODE=no-verify npm run knex:prod:migrate:latest
web: npm run start:prod
web: node dist/src/main.js
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ $ pnpm install

```bash
# development
$ pnpm run start
$ pnpm start

# watch mode
$ npm run start:dev
$ pnpm start:dev

# debug mode
$ pnpm run start:debug
$ pnpm start:debug

# production mode
$ pnpm run start:prod
$ pnpm start:prod
```

### Running the app with docker :whale:
Expand Down Expand Up @@ -74,14 +74,12 @@ src

### Database and ORM

For database we have used PostgreSQL. And for ORM we have used [Knex.js](https://knexjs.org) with [ObjectionJS](https://vincit.github.io/objection.js).
For the database we use **PostgreSQL**. For interacting with the database, we now use [Kysely](https://kysely.dev/), a modern, type-safe SQL query builder for TypeScript.

Knex is an awesome query builder which is closer to SQL. Objection also a thin wrapper around Knex.

For all database migrations please use `snake_case` conversion when creating tables or columns.
We are using [Knex.js](https://knexjs.org) to write and run database migrations. As such, please use `snake_case` when creating tables or columns in your migration scripts.
In PostgreSQL it is natural to work with `snake_case` when writing queries.

Knex will automatically map your `snake_case` names into `camelCase` on application side. Dont use `snake_case` in JS side. Instead always use `camelCase`. Read [more](https://vincit.github.io/objection.js/recipes/snake-case-to-camel-case-conversion.html)
Kysely will automatically map your `snake_case` names into `camelCase` on application side. Don't use `snake_case` in JS side. Instead always use `camelCase`. Read [more](https://kysely-org.github.io/kysely-apidoc/classes/CamelCasePlugin.html)

> Please change the database name in docker-compose file and .env

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ services:
ports:
- 3000:3000
- 9229:9229
working_dir: /usr/src/app
working_dir: /app
volumes:
- .:/usr/src/app
- node_modules:/usr/src/app/node_modules
- dist:/usr/src/app/dist
depends_on:
- db
command: npm run start:debug
command: pnpm run start:debug

db:
image: postgres:latest
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "wavezync-nest-starter",
"version": "0.0.1",
"version": "2.0.0",
"description": "WaveZync Nest Starter",
"author": "Kasun Vithanage <alankasun@gmail.com> (https://kasvith.me)",
"author": "Kasun Vithanage <kasun@wavezync.com> (https://kasvith.me)",
"private": false,
"repository": {
"type": "git",
"url": "https://github.com/wavezync/nestjs-starter"
"url": "https://github.com/wavezync/nestjs-starter.git"
},
"license": "MIT",
"scripts": {
Expand Down Expand Up @@ -45,6 +45,7 @@
"@nestjs/common": "^10.3.3",
"@nestjs/config": "^3.2.0",
"@nestjs/core": "^10.3.3",
"@nestjs/devtools-integration": "^0.1.6",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use latest nestjs as well

"@nestjs/graphql": "^12.1.1",
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-express": "^10.3.3",
Expand All @@ -59,6 +60,7 @@
"graphql": "^16.8.1",
"helmet": "^7.1.0",
"knex": "^3.1.0",
"kysely": "^0.27.3",
"nestjs-pino": "^4.0.0",
"objection": "^3.1.4",
"pg": "^8.11.3",
Expand All @@ -79,6 +81,7 @@
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.24",
"@types/pg": "^8.11.2",
"@types/supertest": "^6.0.2",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^7.1.1",
Expand Down
95 changes: 95 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/@types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { UserDto } from '../modules/user/dtos/user.dto';
import { User } from 'database/schema/users';

declare global {
namespace Express {
interface Request {
user: UserDto;
user: User;
}
}
}
4 changes: 4 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ import { DataloaderService } from 'dataloader/dataloader.service';
import { join } from 'path';
import { formatGraphQLError } from 'common/graphql/errors';
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
import { DevtoolsModule } from '@nestjs/devtools-integration';

@Module({
imports: [
DevtoolsModule.register({
http: process.env.NODE_ENV !== 'production',
}),
ConfigModule.forRoot({
load: [configuration],
isGlobal: true,
Expand Down
7 changes: 7 additions & 0 deletions src/common/interfaces/requestWithRawBody.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Request } from 'express';

interface RequestWithRawBody extends Request {
rawBody: Buffer;
}

export default RequestWithRawBody;
Loading