@pglabs/next-prisma
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

Next Prisma

NPM Version NPM Downloads NPM Collaborators NPM Last Update

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 dev in development mode.

Quick Start

  1. Install the package:
npm install @pglabs/next-prisma
  1. 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);
  1. Run the development server:
npm run dev

It 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
  • 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.
  • dbProvider: string (default: "sqlite")

    • Tell the package which database provider to use. It will be used to create the schema.prisma file. The default is sqlite, but you can also use postgresql, mysql,sqlserver, mariadb, mongodb and cockroachdb.
  • startStudio: boolean (default: false)

    • If set to true, the package will automatically start Prisma Studio when you run next dev in development mode.

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 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 in dist folder
  • pnpm test: Run all unit tests (under the directory tests)
  • pnpm e2e: Run all e2e tests (under the directory e2e)
  • 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

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Package Sidebar

Install

npm i @pglabs/next-prisma

Weekly Downloads

3

Version

0.3.0

License

MIT

Unpacked Size

30.1 kB

Total Files

17

Last publish

Collaborators

  • pierregueroult