Woman wearing Vision Pro
Woman wearing Vision Pro
PPrisma
Created by Striking_Wolf on 7/29/2024 in #help-and-questions
Help for Uncaught TypeError: Failed to resolve module specifier ".prisma/client/index-browser".
There is a Github issue on this: https://github.com/prisma/prisma/issues/12504 with a few workarounds posted. But essentially, you can't use Prisma enum's for some reason in your client-side code.
2 replies
PPrisma
Created by Woman wearing Vision Pro on 5/25/2024 in #help-and-questions
Prisma with Accelerate TypeScript error
bump
8 replies
PPrisma
Created by Woman wearing Vision Pro on 5/25/2024 in #help-and-questions
Prisma with Accelerate TypeScript error
It's not that the query fails, it's that typescript is complaining, so it's more an annoyance than something that's preventing caching/executing queries.
8 replies
PPrisma
Created by Woman wearing Vision Pro on 5/25/2024 in #help-and-questions
Prisma with Accelerate TypeScript error
It is open source but it's a pretty big project and requires a lot of external stuff to get it fully working. If you still want to take a look I'll send the repo.
8 replies
PPrisma
Created by Woman wearing Vision Pro on 5/25/2024 in #help-and-questions
Prisma with Accelerate TypeScript error
Yes I have, multiple times even
8 replies
PPrisma
Created by Woman wearing Vision Pro on 4/4/2024 in #help-and-questions
Optimizing a query
Update: I tried to run the generated SQL directly in Supabase's SQL Editor, no errors! What is going wrong that I get the PrismaClientKnownRequestError only in production?
5 replies
PPrisma
Created by Woman wearing Vision Pro on 4/4/2024 in #help-and-questions
Optimizing a query
Coming back to this. I use Supabase as my database which uses PostgreSQL. I also have a local Supabase docker instance for development. Locally, my Prisma raw sql query runs fine, but in production (Vercel) I'm getting the following error message:
{\"name\":\"PrismaClientKnownRequestError\",\"code\":\"P2010\",\"clientVersion\":\"5.12.1\",\"meta\":{\"code\":\"42804\",\"message\":\"ERROR: column \\\"craftCost\\\" is of type double precision but expression is of type text\\nHINT: You will need to rewrite or cast the expression.\"}}"
{\"name\":\"PrismaClientKnownRequestError\",\"code\":\"P2010\",\"clientVersion\":\"5.12.1\",\"meta\":{\"code\":\"42804\",\"message\":\"ERROR: column \\\"craftCost\\\" is of type double precision but expression is of type text\\nHINT: You will need to rewrite or cast the expression.\"}}"
+server.ts:
const bulkUpdates: BulkUpdateEntries = Object.keys(items).map((item) => {
return {
id: item,
craftCost: items[item]
};
});

await prisma.$transaction([bulkUpdate("Item", bulkUpdates)]);
const bulkUpdates: BulkUpdateEntries = Object.keys(items).map((item) => {
return {
id: item,
craftCost: items[item]
};
});

await prisma.$transaction([bulkUpdate("Item", bulkUpdates)]);
bulkUpdates.ts:
import { type PrismaPromise } from "@prisma/client";

export type BulkUpdateEntry = {
id: number | string;
[key: string]: number | string | boolean | Date;
};
export type BulkUpdateEntries = BulkUpdateEntry[];

export function bulkUpdate(tableName: string, entries: BulkUpdateEntries): PrismaPromise<number> {
if (entries.length === 0) return prisma.$executeRawUnsafe(`SELECT 1;`);

const fields = Object.keys(entries[0]!).filter((key) => key !== "id");
const setSql = fields.map((field) => `"${field}" = data."${field}"`).join(", ");

const valuesSql = entries
.map((entry) => {
const values = fields.map((field) => {
const value = entry[field];
if (typeof value === "string") {
// Handle strings and escape single quotes
return `'${value.replace(/'/g, "''")}'`;
} else if (value instanceof Date) {
// Convert Date to ISO 8601 string format
return `'${value.toISOString()}'`;
}
// Numbers and booleans are used as-is
return value;
});

return `('${entry.id}', ${values.join(", ")})`;
})
.join(", ");

const sql = `
UPDATE "${tableName}"
SET ${setSql}
FROM (VALUES ${valuesSql}) AS data(id, ${fields.map((field) => `"${field}"`).join(", ")})
WHERE "${tableName}".id::text = data.id;
`;

return prisma.$executeRawUnsafe(sql);
}
import { type PrismaPromise } from "@prisma/client";

export type BulkUpdateEntry = {
id: number | string;
[key: string]: number | string | boolean | Date;
};
export type BulkUpdateEntries = BulkUpdateEntry[];

export function bulkUpdate(tableName: string, entries: BulkUpdateEntries): PrismaPromise<number> {
if (entries.length === 0) return prisma.$executeRawUnsafe(`SELECT 1;`);

const fields = Object.keys(entries[0]!).filter((key) => key !== "id");
const setSql = fields.map((field) => `"${field}" = data."${field}"`).join(", ");

const valuesSql = entries
.map((entry) => {
const values = fields.map((field) => {
const value = entry[field];
if (typeof value === "string") {
// Handle strings and escape single quotes
return `'${value.replace(/'/g, "''")}'`;
} else if (value instanceof Date) {
// Convert Date to ISO 8601 string format
return `'${value.toISOString()}'`;
}
// Numbers and booleans are used as-is
return value;
});

return `('${entry.id}', ${values.join(", ")})`;
})
.join(", ");

const sql = `
UPDATE "${tableName}"
SET ${setSql}
FROM (VALUES ${valuesSql}) AS data(id, ${fields.map((field) => `"${field}"`).join(", ")})
WHERE "${tableName}".id::text = data.id;
`;

return prisma.$executeRawUnsafe(sql);
}
What am I doing wrong?
5 replies
PPrisma
Created by Woman wearing Vision Pro on 4/4/2024 in #help-and-questions
Optimizing a query
Thank you! I used the SQL approach and it works perfect! I hope Prisma will support this natively
5 replies