@pglabs/next-prisma v0.3.0
Next Prisma
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)
Features
- 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 devin development mode.
Quick Start
- Install the package:
npm install @pglabs/next-prisma- Update the
next.config.tsfile 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 devIt will automatically init prisma, create a first migration and create the prisma client !
Configuration
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.prismawill 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.prismafile. The default issqlite, but you can also usepostgresql,mysql,sqlserver,mariadb,mongodbandcockroachdb.
- 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 devin development mode.
- If set to
Contributing
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 installMake 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 indistfolderpnpm test: Run all unit tests (under the directorytests)pnpm e2e: Run all e2e tests (under the directorye2e)pnpm lint: Run the linterpnpm format: Format the code with Prettierpnpm 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 devLicense
This project is licensed under the MIT License. See the LICENSE file for more information.