Prisma ORM- create stored procedure

Viewed 15

Using Prisma client 3 I'm trying to create a stored procedure.

The motivation behind it is:

  • I need to query a table that will be created on run time.
  • To do this, I need to use dynamic queries, and I read that stored procedures will be the better practice in this case (pass the table name as a parameter).
  • I would like for each member of my team to have the updated version of the stored procedure (like all the tables in Prisma)

So, what I've decided to do is to create the stored procedure with prisma.$executeRaw when the app starts and call it when I need.

The code: let prisma = new PrismaClient();

let res = await prisma.$executeRawUnsafe(`
  CREATE PROCEDURE \`module-events\`.GetAllProducts()
  BEGIN
    select 555;
  END
`);

The result:

Invalid `prisma.$executeRaw()` invocation:

Raw query failed. Code: `1295`. Message: `This command is not supported in the prepared statement protocol yet`

As you can see the $executeRawUnsafe() returns the same results. Is there any way to create a stored procedure with Prisma? Is there a way to run a "free style" query that is not limited by Prisma?

I understood from this answer that it is possible to create the stored procedure:

You could also use $executeRaw to generate the stored procedure or use the tool/CLI of your choice.

0 Answers
Related