|
| 1 | +# Prisma Client Example: Vitest + Node.js + ESM |
| 2 | + |
| 3 | +This project showcases how to use the Prisma ORM with the `prisma-client` generator in an TypeScript test suite using [Vitest 3](https://vitest.dev/) in an ESM Node.js environment. |
| 4 | + |
| 5 | +## Tech Stack |
| 6 | + |
| 7 | +- Next.js 15 |
| 8 | + - Runtime: Node.js 20.19.0 |
| 9 | + - Test runner: Vitest 3 |
| 10 | + - `package.json` contains `{ "type": "module" }` |
| 11 | +- Prisma Client with the `prisma-client` generator |
| 12 | + See the [Prisma schema file](./prisma/schema.prisma) for details. |
| 13 | + |
| 14 | + ```prisma |
| 15 | + generator client { |
| 16 | + provider = "prisma-client" |
| 17 | + output = "../src/generated/prisma" |
| 18 | + previewFeatures = ["driverAdapters", "queryCompiler"] |
| 19 | + } |
| 20 | +
|
| 21 | + datasource db { |
| 22 | + provider = "sqlite" |
| 23 | + url = "file:./dev.db" |
| 24 | + } |
| 25 | + ``` |
| 26 | + |
| 27 | +## Getting started |
| 28 | + |
| 29 | +### 1. Clone the repository |
| 30 | + |
| 31 | +Clone the repository, navigate into it and install dependencies: |
| 32 | + |
| 33 | +``` |
| 34 | +git clone git@github.com:prisma/prisma-examples.git --depth=1 |
| 35 | +cd prisma-examples/generator-prisma-client/vitest-esm-nodejs |
| 36 | +pnpm install |
| 37 | +``` |
| 38 | + |
| 39 | +### 2. Generate Prisma Client |
| 40 | + |
| 41 | +Run: |
| 42 | + |
| 43 | +``` |
| 44 | +pnpm prisma generate |
| 45 | +``` |
| 46 | + |
| 47 | +### 3. Test the project |
| 48 | + |
| 49 | +Run |
| 50 | + |
| 51 | +``` |
| 52 | +pnpm test |
| 53 | +``` |
| 54 | + |
| 55 | +Your output should look similar to the following: |
| 56 | + |
| 57 | +```sh |
| 58 | +Prisma schema loaded from prisma/schema.prisma |
| 59 | +Datasource "db": SQLite database "dev.db" at "file:./dev.db" |
| 60 | +Running Prisma DB push... |
| 61 | + |
| 62 | + Test Files 0 passed (1) |
| 63 | + Tests 0 passed (0) |
| 64 | + Start at 14:38:33 |
| 65 | + Duration 910ms |
| 66 | +Test database setup completed |
| 67 | + ✓ test/quotes.test.ts (3 tests) 63ms |
| 68 | + ✓ Quotes > should create a quote 50ms |
| 69 | + ✓ Quotes > should find quotes by kind 9ms |
| 70 | + ✓ Quotes > should count total quotes 4ms |
| 71 | + |
| 72 | + Test Files 1 passed (1) |
| 73 | + Tests 3 passed (3) |
| 74 | +``` |
| 75 | + |
| 76 | +## Resources |
| 77 | + |
| 78 | +- Check out the [Prisma docs](https://www.prisma.io/docs) |
| 79 | +- [Join our community on Discord](https://pris.ly/discord?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) to share feedback and interact with other users. |
| 80 | +- [Subscribe to our YouTube channel](https://pris.ly/youtube?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) for live demos and video tutorials. |
| 81 | +- [Follow us on X](https://pris.ly/x?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section) for the latest updates. |
| 82 | +- Report issues or ask [questions on GitHub](https://pris.ly/github?utm_source=github&utm_medium=prisma_examples&utm_content=next_steps_section). |
0 commit comments