Update prisma guide

This commit is contained in:
Colin McDonnell
2023-09-28 11:27:08 -07:00
parent 387f1260c9
commit e62fef6765
2 changed files with 33 additions and 10 deletions

View File

@@ -11,17 +11,17 @@ name: Get started using Prisma
Prisma works out of the box with Bun. First, create a directory and initialize it with `bun init`.
```bash
mkdir prisma-app
cd prisma-app
bun init
$ mkdir prisma-app
$ cd prisma-app
$ bun init
```
---
Then add Prisma as a dependency.
Then install the Prisma CLI (`prisma`) and Prisma Client (`@prisma/client`) as dependencies.
```bash
bun add prisma
$ bun add prisma @prisma/client
```
---
@@ -29,7 +29,7 @@ bun add prisma
We'll use the Prisma CLI with `bunx` to initialize our schema and migration directory. For simplicity we'll be using an in-memory SQLite database.
```bash
bunx prisma init --datasource-provider sqlite
$ bunx prisma init --datasource-provider sqlite
```
---
@@ -60,14 +60,37 @@ Then generate and run initial migration.
This will generate a `.sql` migration file in `prisma/migrations`, create a new SQLite instance, and execute the migration against the new instance.
```bash
bunx prisma migrate dev --name init
$ bunx prisma migrate dev --name init
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": SQLite database "dev.db" at "file:./dev.db"
SQLite database dev.db created at file:./dev.db
Applying migration `20230928182242_init`
The following migration(s) have been created and applied from new schema changes:
migrations/
└─ 20230928182242_init/
└─ migration.sql
Your database is now in sync with your schema.
✔ Generated Prisma Client (v5.3.1) to ./node_modules/@prisma/client in 41ms
```
---
Prisma automatically generates our _Prisma client_ whenever we execute a new migration. The client provides a fully typed API for reading and writing from our database.
As indicated in the output, Prisma re-generates our _Prisma client_ whenever we execute a new migration. The client provides a fully typed API for reading and writing from our database. You can manually re-generate the client with the Prisma CLI.
It can be imported from `@prisma/client`.
```sh
$ bunx prisma generate
```
---
We can import the generated client from `@prisma/client`.
```ts#src/index.ts
import {PrismaClient} from "@prisma/client";