30
loading...
This website collects cookies to deliver better user experience
prisma/schema.prisma
file and append the following snippet.model Post {
id Int @id @default(autoincrement())
title String
content String
published Boolean @default(false)
createAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("posts")
}
@id
) and it must be auto-generated (@default(autoincrement())
)@updatedAt
)@@map("posts")
)npx prisma generate
@prisma/client
, and creates a folder .prisma
inside of your node_modules folder.@prisma/client
is the package that contains the client to connect to your database, whereas, the .prisma folder contains a file index.d.ts
that describes the post Entity and all the possible functions to work with this Entity.posts
and to do this let's create a file called index.ts
inside the src folder and copy the following code. (src/index.ts
)import { PrismaClient } from "@prisma/client";
async function main() {
const prisma = new PrismaClient();
try {
const posts = await prisma.post.findMany();
console.log({ posts });
} finally {
prisma.$disconnect();
}
}
main();
package.json
file....
"scripts": {
"dev": "ts-node ./src/index.ts"
},
...
yarn dev