Last active
February 20, 2023 14:55
-
-
Save junkor-1011/290e17b0b6fd74bcb3424b4631c9ac62 to your computer and use it in GitHub Desktop.
Prisma @Map test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DATABASE_URL="postgresql://postgres:password@localhost:5432/appdb?schema=app&connection_limit=1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .tmp | |
| tmp | |
| .temp | |
| temp | |
| pnpm-lock.yaml | |
| migrations | |
| ### Node ### | |
| # Logs | |
| logs | |
| *.log | |
| npm-debug.log* | |
| .pnpm-debug.log* | |
| # Diagnostic reports (https://nodejs.org/api/report.html) | |
| report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | |
| # Runtime data | |
| pids | |
| *.pid | |
| *.seed | |
| *.pid.lock | |
| # Dependency directories | |
| node_modules/ | |
| jspm_packages/ | |
| # TypeScript cache | |
| *.tsbuildinfo | |
| # Optional npm cache directory | |
| .npm | |
| # Optional REPL history | |
| .node_repl_history | |
| # Output of 'npm pack' | |
| *.tgz | |
| # dotenv environment variable files | |
| .env | |
| .env.development.local | |
| .env.test.local | |
| .env.production.local | |
| .env.local | |
| ### Vim ### | |
| # Swap | |
| [._]*.s[a-v][a-z] | |
| !*.svg # comment out if you don't need vector files | |
| [._]*.sw[a-p] | |
| [._]s[a-rt-v][a-z] | |
| [._]ss[a-gi-z] | |
| [._]sw[a-p] | |
| # Session | |
| Session.vim | |
| Sessionx.vim | |
| # Temporary | |
| .netrwhist | |
| # Auto-generated tag files | |
| tags | |
| # Persistent undo | |
| [._]*.un~ | |
| ### VisualStudioCode ### | |
| .vscode/* | |
| !.vscode/settings.json | |
| !.vscode/tasks.json | |
| !.vscode/launch.json | |
| !.vscode/extensions.json | |
| !.vscode/*.code-snippets | |
| # Local History for Visual Studio Code | |
| .history/ | |
| # Built Visual Studio Code Extensions | |
| *.vsix | |
| ### VisualStudioCode Patch ### | |
| # Ignore all local history of files | |
| .history | |
| .ionide |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { PrismaClient } from '@prisma/client'; | |
| const prisma = new PrismaClient({ | |
| log: ['query', 'warn', 'error'], | |
| }); | |
| await prisma.$transaction([ | |
| prisma.user.deleteMany(), | |
| ]); | |
| await prisma.$disconnect(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: '3.8' | |
| services: | |
| postgres: | |
| image: postgres:14.6-alpine | |
| container_name: postgres | |
| ports: | |
| - 5432:5432 | |
| volumes: | |
| - ./.tmp/data:/var/lib/postgresql/data | |
| environment: | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: password | |
| POSTGRES_INITDB_ARGS: '--encoding=UTF-8' | |
| hostname: postgres | |
| restart: 'no' | |
| user: root | |
| # networks: | |
| # - db_network | |
| # pgadmin4: | |
| # image: dpage/pgadmin4:6.15 | |
| # container_name: pgadmin4 | |
| # ports: | |
| # - 8080:80 | |
| # environment: | |
| # PGADMIN_DEFAULT_EMAIL: [email protected] | |
| # PGADMIN_DEFAULT_PASSWORD: p@ssword | |
| # hostname: pgadmin4 | |
| # depends_on: | |
| # - postgres | |
| # restart: 'no' | |
| # networks: | |
| # - db_network | |
| # | |
| # networks: | |
| # db_network: | |
| # driver: bridge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "experiment", | |
| "version": "1.0.0", | |
| "description": "", | |
| "type": "module", | |
| "packageManager": "[email protected]", | |
| "main": "index.js", | |
| "scripts": { | |
| "generate": "dotenv -e .env -e .env.default -- prisma generate", | |
| "studio": "dotenv -e .env -e .env.default -- prisma studio", | |
| "seed": "dotenv -e .env -e .env.default -- tsx seed.ts", | |
| "delete": "dotenv -e .env -e .env.default -- tsx delete.ts", | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "private": true, | |
| "devDependencies": { | |
| "@types/node": "^18.14.0", | |
| "dotenv-cli": "^7.0.0", | |
| "prisma": "^4.10.1", | |
| "tsx": "^3.12.3", | |
| "typescript": "^4.9.5" | |
| }, | |
| "dependencies": { | |
| "@prisma/client": "^4.10.1" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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" | |
| binaryTargets = ["native", "rhel-openssl-1.0.x"] | |
| } | |
| datasource db { | |
| provider = "postgresql" | |
| url = env("DATABASE_URL") | |
| } | |
| model User { | |
| id Int @id @default(autoincrement()) @map("_id") | |
| userId String @unique @map("user_id") @db.VarChar(32) | |
| role Role @default(USER) | |
| message String? @db.VarChar(32) | |
| createdAt DateTime @default(now()) @map("created_at") | |
| updatedAt DateTime @default(now()) @map("updated_at") | |
| @@map("users") | |
| } | |
| enum Role { | |
| ADMIN | |
| USER | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { type Prisma, PrismaClient } from '@prisma/client'; | |
| const prisma = new PrismaClient({ | |
| log: ['query', 'warn', 'error'], | |
| }); | |
| const usersData = [ | |
| { | |
| userId: 'user00x', | |
| }, | |
| { | |
| userId: 'user00z', | |
| message: 'hyper-message', | |
| role: 'ADMIN', | |
| }, | |
| ] satisfies Prisma.UserCreateManyInput[]; | |
| await prisma.$transaction([ | |
| prisma.user.createMany({ | |
| data: usersData, | |
| skipDuplicates: true, | |
| }), | |
| ]); | |
| await prisma.$disconnect(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
| { | |
| "compilerOptions": { | |
| "target": "esnext", | |
| "module": "esnext", | |
| "moduleResolution": "nodenext", | |
| "esModuleInterop": true, | |
| "forceConsistentCasingInFileNames": true, | |
| "strict": true, | |
| "noEmit": true, | |
| "skipLibCheck": true | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment