Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed: multiple client instances in dev #11

Merged
merged 2 commits into from Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/prisma.ts
@@ -0,0 +1,8 @@
import { PrismaClient } from '@prisma/client'

// create only one prisma client instance for development
const prisma = global.prisma || new PrismaClient()

if (process.env.NODE_ENV !== 'production') global.prisma = prisma

export default prisma
2 changes: 1 addition & 1 deletion pages/api/auth/[...nextauth].ts
@@ -1,5 +1,5 @@
import { PrismaAdapter } from '@next-auth/prisma-adapter'
import { prisma } from 'prisma/index'
import prisma from 'lib/prisma'
import NextAuth from 'next-auth'
import GithubProvider from 'next-auth/providers/github'

Expand Down
2 changes: 1 addition & 1 deletion pages/api/hello.ts
@@ -1,7 +1,7 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { User } from '@prisma/client'
import type { NextApiRequest, NextApiResponse } from 'next'
import { prisma } from 'prisma/index'
import prisma from 'lib/prisma'

export default async function handler (req: NextApiRequest, res: NextApiResponse<User[]>) {
const users: User[] = await prisma.user.findMany({})
Expand Down
3 changes: 0 additions & 3 deletions prisma/index.tsx

This file was deleted.