|
With Prisma, it is recommended in development to keep a copy of the prisma client in global. This is a best practive applied in other frameworks such as Next or Remix: ...
declare global {
var __db__: PrismaClient;
}
// this is needed because in development we don't want to restart
// the server with every change, but we want to make sure we don't
// create a new connection to the DB with every change either.
// in production we'll have a single connection to the DB.
if (process.env.NODE_ENV === "production") {
prisma = getClient();
} else {
if (!global.__db__) { // <--- this is line 17
global.__db__ = getClient();
}
prisma = global.__db__;
}
...But I get the following error in console: I believe this comment vitejs/vite#2618 (comment) is part of the response, but it is unclear how to fix that. I suppose there should be a workaround to have such best practice applied with SolidStart. |
Answered by
binajmen
Dec 17, 2022
Replies: 2 comments
|
This happens when I create the following route action: ...
export default function Index() {
const users = useRouteData<typeof routeData>();
const [_, { Form }] = createRouteAction(async (formData: FormData) => {
const email = formData.get("email");
await prisma.user.create({
data: {
email: email as string,
},
});
});
...I suppose the bundling of the route action happens before the |
0 replies
|
My bad, I know why! |
0 replies
Answer selected by
binajmen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My bad, I know why!
createServerAction$for the win!