Quick Start
After installing the package, checkout the sidebase "with Prisma" quick start or the more detailed Prisma description to get further information.
This page summarizes covers some additional information related to endpoint-usage and testing.
Use Prisma in Endpoints
To use Prisma in one of your endpoints, you can now easily:
// file: ~/server/api/example.get.tsexport default eventHandler(event => event.context.prisma.example.findMany())
This also works in your app-middleware!
Database Setup for Jest / Vitest tests
The prisma-integration layer also includes resetDatabase
which is a function that quickly bootstrap a clean database, e.g., for a testing setup. Here's how to use it:
import { describe, beforeEach } from 'vitest'import { resetDatabase } from '~/prisma/utils'beforeEach(() => { resetDatabase()})describe('test that involves the database', () => { // Add code that depends on a setup, clean database here. // You can also add multiple tests, they won't corrupt each other as the database is cleaned up after every go})
resetDatabase
drops all data of the database that is currently configured via the environment variable DATABASE_URL
, never run resetDatabase
in production.Table of Contents