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

d1 support #36

Open
acidjazz opened this issue Sep 8, 2024 · 4 comments
Open

d1 support #36

acidjazz opened this issue Sep 8, 2024 · 4 comments
Assignees
Labels

Comments

@acidjazz
Copy link

acidjazz commented Sep 8, 2024

I'm working on getting CloudFflare d1 support for Prisma with Nuxt Hub, I've created this issue to help track my progress, so far this version of server/utils/prisma.ts is working for me.

import { PrismaD1 } from '@prisma/adapter-d1'
import { PrismaClient } from '@prisma/client'
import type { D1Database } from '@nuxthub/core'
import type { EventHandlerRequest, H3Event } from 'h3'
import models from '../models/index'

export function useDB(event: H3Event<EventHandlerRequest>): D1Database {
  return event.context.cloudflare.env.DB as D1Database
}

let prismaClient: PrismaClient
export function usePrisma(event: H3Event<EventHandlerRequest>) {
  if (!prismaClient) {
    const adapter = new PrismaD1(useDB(event))
    prismaClient = new PrismaClient({ adapter })
  }
  return prismaClient
}

My current challenge is how to run local migrations:

  • Cannot use npx prisma migrate because it doesn't harness the d1 driver
  • Cannot use wrangler because it goes after the .sqlite files in .wrangler and not .data

Any suggestions/tips/etc would be appreciated, I'll update this issue as I progress

@robert-hoffmann
Copy link

bump

i like prisma, but switching to nuxt/nuxthub currently
would like to see prisma integrated with D1 too 👍

@robert-hoffmann
Copy link

hmmm...

nuxthub says this is implemented on prisma's side, and they are currently reviewing the docs for nuxt

https://volta.net/nuxt-hub/core/issues/38

I found this on cloudflare, but doesn't seem related to nuxt

https://developers.cloudflare.com/d1/tutorials/d1-and-prisma-orm

@acidjazz
Copy link
Author

acidjazz commented Sep 23, 2024

BTW a full working version of nuxt+prisma+hub+d1 can be found here https://github.com/fumeapp/bio

Please note that until this gets in the module, I had to remove it.

@robert-hoffmann
Copy link

BTW a full working version of nuxt+prisma+hub+d1 can be found here https://github.com/fumeapp/bio

Please note that until this gets in the module, I had to remove it.

Tnx, will have a look 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants