Skip to content

d1 support #36

@acidjazz

Description

@acidjazz

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions