Loving both Prisma and Next.js but struggling to make them work together? This package is for you!
(is now supposed to work for both webpack and turbopack)
-
Automatic Prisma Client Generation: Automatically generates the Prisma client when you run
next dev
. - Automatic Singleton Client Instance: Ensures that the Prisma client is a singleton instance, preventing multiple connections to the database.
- Complete Automatic Initialization: You do not need to worry about initializing the Prisma client. It is done automatically for you, in the folder of your choice.
-
Automatic Studio Start: Automatically starts Prisma Studio when you run
next dev
in development mode.
- Install the package:
npm install @pglabs/next-prisma
- Update the
next.config.ts
file of your Next.js project:
import { withNextPrisma } from "@pglabs/next-prisma";
const nextConfig = {
// Your Next.js config
};
export default withNextPrisma(nextConfig);
- Run the development server:
npm run dev
It will automatically init prisma, create a first migration and create the prisma client !
You can configure the package by adding a second argument to the withNextPrisma
function. The configuration object can contain the following properties:
-
runMigration
: boolean (default: true)- If set to
true
, the package will automatically run an initial migration if the migrations folder does'nt exists
- If set to
-
prismaRoot
: string (default: "prisma")- The folder where prisma lives, where the
schema.prisma
will be created and where the migrations and clients will be stored.
- The folder where prisma lives, where the
-
dbProvider
: string (default: "sqlite")- Tell the package which database provider to use. It will be used to create the
schema.prisma
file. The default issqlite
, but you can also usepostgresql
,mysql
,sqlserver
,mariadb
,mongodb
andcockroachdb
.
- Tell the package which database provider to use. It will be used to create the
-
startStudio
: boolean (default: false)- If set to
true
, the package will automatically start Prisma Studio when you runnext dev
in development mode.
- If set to
If you want to contribute to the project, feel free to open an issue or a pull request. We welcome any contributions, whether it's bug fixes, new features, or improvements to the documentation.
Read the contributing guide and code of conduct for more information.
git clone https://github.com/pglabs/next-prisma.git
cd next-prisma
pnpm install
Make sure to use pnpm
to install the dependencies or at least make sure to have it installed globally since some tests require it ( most of them actually, especially the one under the directory e2e
, that init several next.js projects and test the package usecase scenarios).
Here are the available scripts:
-
pnpm build
: Build the package indist
folder -
pnpm test
: Run all unit tests (under the directorytests
) -
pnpm e2e
: Run all e2e tests (under the directorye2e
) -
pnpm lint
: Run the linter -
pnpm format
: Format the code with Prettier -
pnpm release
: Release a new version of the package (that's my job there)
To test the project during your development project feel free to duplicate the e2e/fixture/starter
folder and run the following command:
pnpm dev
This project is licensed under the MIT License. See the LICENSE file for more information.