Skip to content

Commit ee91030

Browse files
committed
update hackernews app to use drizzle and postgres
1 parent f32ad6d commit ee91030

File tree

20 files changed

+620
-334
lines changed

20 files changed

+620
-334
lines changed

examples/hackernews/.env.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PG_CONNECTION_STRING=postgres://postgres:postgres@localhost:5432/postgres

examples/hackernews/.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules
22
# Keep environment variables out of version control
33
.env
4-
prisma/migrations/migration_lock.toml
5-
prisma/*.db*
4+
.pg-data

examples/hackernews/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Stack
44

55
- GraphQL Yoga
6-
- Prisma
6+
- Drizzle
77

88
## Tutorial
99

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: '3.8'
2+
services:
3+
db:
4+
image: postgres:14.12-alpine
5+
networks:
6+
- 'stack'
7+
healthcheck:
8+
test: ['CMD-SHELL', 'pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}']
9+
interval: 10s
10+
timeout: 5s
11+
retries: 5
12+
environment:
13+
POSTGRES_USER: postgres
14+
POSTGRES_PASSWORD: postgres
15+
POSTGRES_DB: postgres
16+
PGDATA: /var/lib/postgresql/data
17+
volumes:
18+
- ./.pg-data:/var/lib/postgresql/data
19+
ports:
20+
- '5432:5432'
21+
22+
networks:
23+
stack: {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineConfig } from 'drizzle-kit';
2+
3+
export default defineConfig({
4+
dialect: 'postgresql',
5+
out: './src/drizzle',
6+
schema: './src/drizzle/schema.ts',
7+
dbCredentials: {
8+
host: process.env.DB_HOST!,
9+
port: Number(process.env.DB_PORT!),
10+
user: process.env.DB_USERNAME!,
11+
password: process.env.DB_PASSWORD!,
12+
database: process.env.DB_NAME!,
13+
},
14+
// Print all statements
15+
verbose: true,
16+
// Always ask for confirmation
17+
strict: true,
18+
});

examples/hackernews/package.json

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
11
{
22
"name": "example-hackernews",
33
"version": "4.3.0",
4-
"description": "",
5-
"author": "",
6-
"license": "ISC",
4+
"type": "module",
5+
"description": "Hackernews API Clone using GraphQL Yoga.",
6+
"author": "Laurin Quast",
7+
"license": "MIT",
78
"private": true,
9+
"files": [
10+
"Dockerfile",
11+
"dist/src",
12+
"package.json",
13+
"prisma"
14+
],
815
"keywords": [],
916
"scripts": {
17+
"build": "tsc",
1018
"check": "tsc --pretty --noEmit",
11-
"dev": "cross-env NODE_ENV=development ts-node-dev --exit-child --respawn src/main.ts",
12-
"migrate": "prisma migrate dev",
13-
"postinstall": "prisma generate",
19+
"dev": "cross-env NODE_ENV=development node --loader=ts-node/esm --env-file .env --watch src/main.ts",
20+
"migrate": "pnpm drizzle-kit generate",
1421
"start": "ts-node src/main.ts"
1522
},
1623
"dependencies": {
24+
"drizzle-orm": "0.31.2",
1725
"graphql": "16.6.0",
18-
"graphql-yoga": "workspace:*"
26+
"graphql-yoga": "workspace:*",
27+
"pg": "8.12.0"
1928
},
2029
"devDependencies": {
21-
"@prisma/client": "5.13.0",
22-
"@prisma/internals": "5.13.0",
23-
"@prisma/migrate": "5.13.0",
2430
"@types/node": "18.16.16",
31+
"@types/pg": "8.11.6",
2532
"cross-env": "7.0.3",
26-
"prisma": "5.13.0",
33+
"drizzle-kit": "0.22.7",
2734
"ts-node": "10.9.1",
2835
"ts-node-dev": "2.0.0",
2936
"typescript": "5.1.6"

examples/hackernews/prisma/migrations/20220223111842_init/migration.sql

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

examples/hackernews/prisma/migrations/20220223114846_comments/migration.sql

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

examples/hackernews/prisma/schema.prisma

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

examples/hackernews/src/context.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
import { PrismaClient } from '@prisma/client';
2-
3-
const prisma = new PrismaClient();
1+
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
42

53
export type GraphQLContext = {
6-
prisma: PrismaClient;
4+
db: NodePgDatabase;
75
};
8-
9-
export async function createContext(): Promise<GraphQLContext> {
10-
return {
11-
prisma,
12-
};
13-
}

0 commit comments

Comments
 (0)