Skip to content

Commit 9429d65

Browse files
authored
Merge pull request #12 from wavezync/feat/kysely
feat: Kysely upgrade
2 parents 8788840 + 5268bbf commit 9429d65

37 files changed

+1758
-778
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM node:20-alpine AS base
33
ENV HUSKY=0
44
ENV PNPM_HOME="/pnpm"
55
ENV PATH="$PNPM_HOME:$PATH"
6+
RUN npm i -g corepack@latest
67
RUN corepack enable
78

89
FROM base AS build

Procfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
release: PGSSLMODE=no-verify npm run knex:prod:migrate:latest
2-
web: npm run start:prod
1+
release: PGSSLMODE=no-verify pnpm run kysely:prod:migrate:latest
2+
web: node dist/src/main.js

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ $ pnpm install
2020

2121
```bash
2222
# development
23-
$ pnpm run start
23+
$ pnpm start
2424

2525
# watch mode
26-
$ npm run start:dev
26+
$ pnpm start:dev
2727

2828
# debug mode
29-
$ pnpm run start:debug
29+
$ pnpm start:debug
3030

3131
# production mode
32-
$ pnpm run start:prod
32+
$ pnpm start:prod
3333
```
3434

3535
### Running the app with docker :whale:
@@ -74,14 +74,11 @@ src
7474

7575
### Database and ORM
7676

77-
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).
77+
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.
7878

79-
Knex is an awesome query builder which is closer to SQL. Objection also a thin wrapper around Knex.
79+
We now also handle migrations using [kysely-ctl](https://github.com/kysely-org/kysely-ctl), the official CLI tool for Kysely. Migration files are written in TypeScript and reside in the `src/database/migrations` directory.
8080

81-
For all database migrations please use `snake_case` conversion when creating tables or columns.
82-
In PostgreSQL it is natural to work with `snake_case` when writing queries.
83-
84-
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)
81+
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)
8582

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

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ services:
1010
ports:
1111
- 3000:3000
1212
- 9229:9229
13-
working_dir: /usr/src/app
13+
working_dir: /app
1414
volumes:
1515
- .:/usr/src/app
1616
- node_modules:/usr/src/app/node_modules
1717
- dist:/usr/src/app/dist
1818
depends_on:
1919
- db
20-
command: npm run start:debug
20+
command: pnpm run start:debug
2121

2222
db:
2323
image: postgres:latest

knexfile.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

kysely.config.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { defineConfig, getKnexTimestampPrefix } from 'kysely-ctl';
2+
import { Pool } from 'pg';
3+
4+
export default defineConfig({
5+
dialect: 'pg',
6+
dialectConfig: {
7+
pool: new Pool({
8+
connectionString: process.env.DATABASE_URL,
9+
}),
10+
},
11+
migrations: {
12+
migrationFolder: './src/database/migrations',
13+
allowJS: true,
14+
getMigrationPrefix: getKnexTimestampPrefix,
15+
},
16+
seeds: {
17+
allowJS: true,
18+
getSeedPrefix: getKnexTimestampPrefix,
19+
seedFolder: './src/database/seeds',
20+
},
21+
});

package.json

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "wavezync-nest-starter",
3-
"version": "0.0.1",
3+
"version": "2.0.0",
44
"description": "WaveZync Nest Starter",
5-
"author": "Kasun Vithanage <alankasun@gmail.com> (https://kasvith.me)",
5+
"author": "Kasun Vithanage <kasun@wavezync.com> (https://kasvith.me)",
66
"private": false,
77
"repository": {
88
"type": "git",
9-
"url": "https://github.com/wavezync/nestjs-starter"
9+
"url": "https://github.com/wavezync/nestjs-starter.git"
1010
},
1111
"license": "MIT",
1212
"scripts": {
@@ -23,33 +23,32 @@
2323
"test:cov": "jest --coverage",
2424
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
2525
"test:e2e": "jest --config ./test/jest-e2e.json",
26-
"knex": "knex",
27-
"knex:migrate:latest": "knex migrate:latest",
28-
"knex:migrate:up": "knex migrate:up",
29-
"knex:migrate:down": "knex migrate:down",
30-
"knex:migrate:rollback": "knex migrate:rollback",
31-
"knex:migrate:rollback:all": "knex migrate:rollback --all",
32-
"knex:prod": "knex --knexfile dist/knexfile.js",
33-
"knex:prod:migrate:latest": "pnpm run knex:prod migrate:latest",
34-
"knex:prod:migrate:up": "pnpm run knex:prod migrate:up",
35-
"knex:prod:migrate:down": "pnpm run knex:prod migrate:down",
36-
"knex:prod:migrate:rollback": "pnpm run knex:prod migrate:rollback",
37-
"knex:prod:migrate:rollback:all": "pnpm run knex:prod migrate:rollback --all",
26+
"kysely": "kysely",
27+
"kysely:migrate:latest": "kysely migrate:latest",
28+
"kysely:migrate:up": "kysely migrate:up",
29+
"kysely:migrate:down": "kysely migrate:down",
30+
"kysely:migrate:rollback:all": "kysely migrate:rollback --all",
31+
"kysely:prod": "kysely --config dist/kysely.config.js",
32+
"kysely:prod:migrate:latest": "pnpm run kysely:prod migrate:latest",
33+
"kysely:prod:migrate:up": "pnpm run kysely:prod migrate:up",
34+
"kysely:prod:migrate:down": "pnpm run kysely:prod migrate:down",
35+
"kysely:prod:migrate:rollback:all": "pnpm run kysely:prod migrate:rollback --all",
3836
"doc:generate": "npx compodoc -p tsconfig.json -n \"Documentation\"",
3937
"doc:serve": "npx compodoc -p tsconfig.json -n \"Documentation\" -s"
4038
},
4139
"dependencies": {
4240
"@apollo/server": "^4.10.0",
4341
"@nanogiants/nestjs-swagger-api-exception-decorator": "^1.6.11",
44-
"@nestjs/apollo": "^12.1.0",
45-
"@nestjs/common": "^10.3.3",
46-
"@nestjs/config": "^3.2.0",
47-
"@nestjs/core": "^10.3.3",
48-
"@nestjs/graphql": "^12.1.1",
49-
"@nestjs/jwt": "^10.2.0",
50-
"@nestjs/platform-express": "^10.3.3",
51-
"@nestjs/swagger": "^7.3.0",
52-
"@nestjs/terminus": "^10.2.3",
42+
"@nestjs/apollo": "^13.0.2",
43+
"@nestjs/common": "^11.0.9",
44+
"@nestjs/config": "^4.0.0",
45+
"@nestjs/core": "^11.0.9",
46+
"@nestjs/devtools-integration": "^0.2.0",
47+
"@nestjs/graphql": "^13.0.2",
48+
"@nestjs/jwt": "^11.0.0",
49+
"@nestjs/platform-express": "^11.0.9",
50+
"@nestjs/swagger": "^11.0.3",
51+
"@nestjs/terminus": "^11.0.0",
5352
"bcrypt": "^5.1.1",
5453
"class-transformer": "^0.5.1",
5554
"class-validator": "^0.14.1",
@@ -58,9 +57,8 @@
5857
"find-config": "^1.0.0",
5958
"graphql": "^16.8.1",
6059
"helmet": "^7.1.0",
61-
"knex": "^3.1.0",
60+
"kysely": "^0.27.5",
6261
"nestjs-pino": "^4.0.0",
63-
"objection": "^3.1.4",
6462
"pg": "^8.11.3",
6563
"pino-http": "^9.0.0",
6664
"pino-pretty": "^10.3.1",
@@ -72,13 +70,14 @@
7270
},
7371
"devDependencies": {
7472
"@compodoc/compodoc": "^1.1.23",
75-
"@nestjs/cli": "^10.3.2",
76-
"@nestjs/schematics": "^10.1.1",
77-
"@nestjs/testing": "^10.3.3",
73+
"@nestjs/cli": "^11.0.2",
74+
"@nestjs/schematics": "^11.0.0",
75+
"@nestjs/testing": "^11.0.9",
7876
"@types/bcrypt": "^5.0.2",
7977
"@types/express": "^4.17.21",
8078
"@types/jest": "^29.5.12",
8179
"@types/node": "^20.11.24",
80+
"@types/pg": "^8.11.2",
8281
"@types/supertest": "^6.0.2",
8382
"@types/uuid": "^9.0.8",
8483
"@typescript-eslint/eslint-plugin": "^7.1.1",
@@ -87,6 +86,7 @@
8786
"eslint-config-prettier": "^9.1.0",
8887
"eslint-plugin-prettier": "^5.1.3",
8988
"jest": "^29.7.0",
89+
"kysely-ctl": "^0.11.1",
9090
"prettier": "^3.2.5",
9191
"supertest": "^6.3.4",
9292
"ts-jest": "^29.1.2",

0 commit comments

Comments
 (0)