Woman wearing Vision Pro
Woman wearing Vision Pro
PPrisma
Created by Woman wearing Vision Pro on 5/25/2024 in #help-and-questions
Prisma with Accelerate TypeScript error
When I'm using Prisma with Accelerate, the Prisma types are not generated for the Accelerate extension. Trying to use cacheStrategy results in TS showing the following error:
Type '{ ttl: number; }' is not assignable to type 'never'.ts(2322)
Type '{ ttl: number; }' is not assignable to type 'never'.ts(2322)
I'm using SvelteKit and have the following setup: src/app.d.ts:
import type { PrismaClient } from "@prisma/client";
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces

declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface Platform {}
}
var prisma: PrismaClient;
}

export {};
import type { PrismaClient } from "@prisma/client";
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces

declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface Platform {}
}
var prisma: PrismaClient;
}

export {};
src/lib/server/prisma.ts:
import { PrismaClient } from "@prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";

declare global {
var prisma: PrismaClient;
}

const prisma = global.prisma || new PrismaClient().$extends(withAccelerate());
global.prisma = prisma;

export default prisma;
import { PrismaClient } from "@prisma/client";
import { withAccelerate } from "@prisma/extension-accelerate";

declare global {
var prisma: PrismaClient;
}

const prisma = global.prisma || new PrismaClient().$extends(withAccelerate());
global.prisma = prisma;

export default prisma;
How can I fix this?
8 replies
PPrisma
Created by Woman wearing Vision Pro on 4/4/2024 in #help-and-questions
Optimizing a query
I currently have the following code to update the pricing of the items in the database:
const prismapromises = Object.keys(items).map((item) =>
prisma.minion.update({
where: { id: item },
data: { cost: items[items] }
})
);

await prisma.$transaction(prismapromises);
const prismapromises = Object.keys(items).map((item) =>
prisma.minion.update({
where: { id: item },
data: { cost: items[items] }
})
);

await prisma.$transaction(prismapromises);
This is a cron job that runs every day and I have 700 items. So every day, 700 queries are being executed. This is not great, especially since I'm using Accelerate as this costs 21000 queries a month (700 * 30). I don't know how to optimize this, since updateMany doesn't work with multiple different id's. Any help would be great!
5 replies