#how to use prisma dev

1 messages · Page 1 of 1 (latest)

light bane
#

how do i make this code to work with npx prisma dev --name mydb instead of docker?

import "dotenv/config";
import { PrismaClient } from "@/generated/prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";
import { PrismaPg } from "@prisma/adapter-pg";

import { createThoughtInput } from "./validations/thought";

function createPrisma() {
  const base =
    process.env.NODE_ENV === "production"
      ? new PrismaClient({
          accelerateUrl: process.env.DATABASE_URL!,
        })
      : new PrismaClient({
          adapter: new PrismaPg({
            connectionString: process.env.DATABASE_URL!,
          }),
        });

  return base.$extends(withAccelerate()).$extends({
    query: {
      thought: {
        create: ({ args, query }) => {
          args.data = createThoughtInput.parse(args.data);
          return query(args);
        },
      },
    },
  });
}

const globalForPrisma = globalThis as unknown as {
  prisma?: ReturnType<typeof createPrisma>;
};

export const prisma = globalForPrisma.prisma ?? createPrisma();

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
frail beaconBOT
#

You decided to hold for human wisdom. We'll chime in soon! Meanwhile, #ask-ai is there if you need a quick second opinion.

hidden hawk