Skip to content

Commit

Permalink
feat: with prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykomiotek committed Feb 1, 2024
1 parent 170e0b7 commit 6e3c2fd
Show file tree
Hide file tree
Showing 24 changed files with 314 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=postgres://postgres:pass123@localhost:5432/jobboard
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

.env

# postgres data
/db-data

# compiled output
dist
tmp
Expand Down
1 change: 1 addition & 0 deletions apps/jobboard/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL="postgres://postgres:pass123@localhost:5432/jobboard"
1 change: 1 addition & 0 deletions apps/jobboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env.local
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3'
services:
db:
image: postgres
restart: always
ports:
- '5432:5432'
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: pass123
POSTGRES_DB: jobboard
volumes:
- ./db-data:/var/lib/postgresql/data
redis:
image: redis
ports:
- '6379:6379'
restart: always
18 changes: 18 additions & 0 deletions libs/prisma-client/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
3 changes: 3 additions & 0 deletions libs/prisma-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# prisma-client

This library was generated with [Nx](https://nx.dev).
15 changes: 15 additions & 0 deletions libs/prisma-client/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "prisma-client",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/prisma-client/src",
"projectType": "library",
"targets": {
"seed": {
"command": "ts-node ./seed.ts",
"options": {
"cwd": "libs/prisma-client/src/lib"
}
}
},
"tags": []
}
1 change: 1 addition & 0 deletions libs/prisma-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/db';
19 changes: 19 additions & 0 deletions libs/prisma-client/src/lib/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { PrismaClient } from '@prisma/client';

const prismaClientSingleton = () => {
return new PrismaClient({ log: ['query'] });
};

type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;

const globalForPrisma = globalThis as unknown as {
prisma: PrismaClientSingleton | undefined;
};

const prisma = globalForPrisma.prisma ?? prismaClientSingleton();

export default prisma;

if (process.env['NODE_ENV'] !== 'production') {
globalForPrisma.prisma = prisma;
}
13 changes: 13 additions & 0 deletions libs/prisma-client/src/lib/seed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import prisma from './db';

async function main() {}

main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit();
});
19 changes: 19 additions & 0 deletions libs/prisma-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
]
}
10 changes: 10 additions & 0 deletions libs/prisma-client/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"]
}
18 changes: 18 additions & 0 deletions libs/prisma-schema/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
3 changes: 3 additions & 0 deletions libs/prisma-schema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# prisma-schema

This library was generated with [Nx](https://nx.dev).
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- CreateTable
CREATE TABLE "JobOffer" (
"id" SERIAL NOT NULL,
"public_id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"description" TEXT NOT NULL,
"position" TEXT NOT NULL,
"salary" DOUBLE PRECISION NOT NULL,
"employer" TEXT NOT NULL,
"city" VARCHAR(100),

CONSTRAINT "JobOffer_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "JobOffer_public_id_key" ON "JobOffer"("public_id");
3 changes: 3 additions & 0 deletions libs/prisma-schema/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
22 changes: 22 additions & 0 deletions libs/prisma-schema/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model JobOffer {
id Int @id @default(autoincrement())
public_id String @unique @default(uuid())
title String
description String
position String
salary Float
employer String
city String? @db.VarChar(100)
}
40 changes: 40 additions & 0 deletions libs/prisma-schema/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "prisma-schema",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/prisma-schema/src",
"projectType": "library",
"targets": {
"prisma": {
"command": "prisma",
"options": {
"cwd": "libs/prisma-schema"
}
},
"generate-types": {
"command": "prisma generate",
"options": {
"cwd": "libs/prisma-schema"
}
},
"migrate-dev": {
"command": "prisma migrate dev",
"options": {
"cwd": "libs/prisma-schema"
}
},
"migrate-deploy": {
"command": "prisma migrate deploy",
"options": {
"cwd": "libs/prisma-schema"
}
},
"studio": {
"command": "prisma studio",
"options": {
"cwd": "libs/prisma-schema"
}
}

},
"tags": []
}
19 changes: 19 additions & 0 deletions libs/prisma-schema/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
]
}
10 changes: 10 additions & 0 deletions libs/prisma-schema/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dependencies": {
"@heroicons/react": "^2.1.1",
"@hookform/resolvers": "^3.3.4",
"@prisma/client": "^5.9.0",
"next": "14.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down Expand Up @@ -71,6 +72,7 @@
"nx": "17.3.1",
"postcss": "8.4.21",
"prettier": "^2.6.2",
"prisma": "^5.9.0",
"tailwind-merge": "^2.2.1",
"tailwindcss": "3.2.7",
"ts-jest": "^29.1.0",
Expand All @@ -81,4 +83,3 @@
"vitest": "0.34.6"
}
}

54 changes: 54 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: 3 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"skipDefaultLibCheck": true,
"baseUrl": ".",
"paths": {
"@jobboard/common-ui": ["libs/common-ui/src/index.ts"]
"@jobboard/common-ui": ["libs/common-ui/src/index.ts"],
"@jobboard/prisma-client": ["libs/prisma-client/src/index.ts"],
"@jobboard/prisma-schema": ["libs/prisma-schema/src/index.ts"]
}
},
"exclude": ["node_modules", "tmp"]
Expand Down

0 comments on commit 6e3c2fd

Please sign in to comment.