Andrés Rodríguez
09/08/2021, 3:36 PMTRUNCATE command (postgres). However, the example here doesn’t work. Throws the following error:
PrismaClientValidationError: `$queryRaw` is a tag function, please use it like the following:
const result = await prisma.$queryRaw`SELECT * FROM User WHERE id = ${1} OR email = ${'<mailto:user@email.com|user@email.com>'};`
Now, if I make this change:
await prisma.$queryRaw`TRUNCATE TABLE "public"."${tablename}" CASCADE;`;
I get the following error:
Invalid `prisma.queryRaw()` invocation:
Your raw query had an incorrect number of parameters. Expected: `0`, actual: `1`.
I know the other option would be using many deleteMany() but I want to try using TRUNCATE before I get into the weeds there. I’m using the latest versions (3.0.1)Daniel Norman
Andrés Rodríguez
09/08/2021, 4:30 PMAndrés Rodríguez
09/08/2021, 4:32 PMAndrés Rodríguez
09/09/2021, 11:42 AMprisma.$queryRawUnsafe instead of prisma.$queryRawDaniel Norman
Maxi Peñaranda
09/10/2021, 12:44 PMfor await (const { tablename } of tables) {
if (tablename !== '_prisma_migrations') {
try {
const table: string = tablename;
await prisma.$executeRawUnsafe(
['TRUNCATE TABLE', table, 'CASCADE'].join(' ')
);
} catch (error) {
console.log({ error });
}
}
}Maxi Peñaranda
09/10/2021, 12:44 PMAndrés Rodríguez
09/10/2021, 12:49 PMqueryRawUnsafe though not executeAndrés Rodríguez
09/10/2021, 12:50 PMqueryRaw -> queryRawUnsafe