Skip to content

Commit 07f1bae

Browse files
committed
Sesión Prisma
1 parent ab5dad9 commit 07f1bae

File tree

8 files changed

+456
-0
lines changed

8 files changed

+456
-0
lines changed

2023-05-04/hola-prisma/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
# Keep environment variables out of version control
3+
.env

2023-05-04/hola-prisma/package-lock.json

Lines changed: 257 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

2023-05-04/hola-prisma/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "hola-prisma",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@types/node": "^18.16.3",
15+
"prisma": "^4.13.0",
16+
"ts-node": "^10.9.1",
17+
"typescript": "^5.0.4"
18+
},
19+
"dependencies": {
20+
"@prisma/client": "^4.13.0"
21+
}
22+
}

2023-05-04/hola-prisma/prisma/dev.db

44 KB
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
datasource db {
2+
provider = "sqlite"
3+
url = env("DATABASE_URL")
4+
}
5+
6+
generator client {
7+
provider = "prisma-client-js"
8+
}
9+
10+
model Movie {
11+
id Int @id @default(autoincrement())
12+
title String
13+
year Int
14+
duration Int
15+
forFamilies Boolean @default(false)
16+
createdAt DateTime @default(now())
17+
tags Tag[]
18+
details MovieDetails?
19+
20+
@@unique([title, year])
21+
}
22+
23+
model MovieDetails {
24+
id Int @id @default(autoincrement())
25+
description String
26+
27+
movieId Int @unique
28+
movie Movie @relation(references: [id], fields: [movieId])
29+
}
30+
31+
model Tag {
32+
tag String @id
33+
movies Movie[]
34+
}

2023-05-04/hola-prisma/query.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { PrismaClient } from "@prisma/client";
2+
3+
const prisma = new PrismaClient();
4+
5+
console.log(
6+
await prisma.movie.aggregate({
7+
_max: {
8+
year: true,
9+
duration: true,
10+
}
11+
})
12+
);

2023-05-04/hola-prisma/seed.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { PrismaClient } from "@prisma/client";
2+
3+
const prisma: PrismaClient = new PrismaClient();
4+
5+
// const newMovie = await prisma.movie.create({
6+
// data: {
7+
// title: "The Incredibles",
8+
// duration: 124,
9+
// year: 2004,
10+
// }
11+
// })
12+
13+
const newTag = await prisma.tag.create({
14+
data: {
15+
tag: "animation",
16+
}
17+
})
18+
19+
console.log(newTag);

0 commit comments

Comments
 (0)