<@UQT5WQX9S> thanks for hosting streams like these...
# orm-help
p
@Daniel Norman thanks for hosting streams like these:

https://www.youtube.com/watch?v=ogfXx2NfiNo

Very helpful! prisma rainbow I got a question for Ryan (don't see him here on slack) I'd like to host a prisma2 server in a serverless environment, but unlike Ryan showed there, I'd like to use vercel rather than serverless framework. I already went through this guide which worked great, but I have not load tested it in a real production app yet. Ryan pointed out in his talk that the prisma client needs to be instantiated outside of the
handler
so it gets re-used, which makes perfect sense. I'm not aware of how to extract handler functions etc inside a function running on vercel.
🙏 1
r
Hey @Pieter 👋 In the guide that you have pointed out, Prisma Client is instantiated outside the handler as in this function:
Copy code
import { PrismaClient, PrismaClientRequestError } from '@prisma/client'
const prisma = new PrismaClient()

export default async (req, res) => {
  try {
    const createdUser = await prisma.user.create({
      data: req.body
    })
    res.status(200).json(createdUser)
  } catch (e) {
    if (e instanceof PrismaClientRequestError) {
      if (e.code === 'P2002') {
        return res
          .status(409)
          .json({ error: 'A user with this email already exists' })
      }
    }
    console.error(e)
    return res.status(500)
  }
}
p
so the default export is run as a handler under the hood on aws lambda?
And the parts outside of it will be re-used as long as the lambda is warmed?
🤔 1
r
so the default export is run as a handler under the hood on aws lambda?
Yes, for AWS Lambda you can configure the export as per your naming and that needs to be specified with the path of the file.
And the parts outside of it will be re-used as long as the lambda is warmed?
Yes that’s correct. You can read more about this here. I’m not sure about how Vercel works, but it should be somewhat similar
p
Thanks, I appreciate it
💯 2