prisma / prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PANIC: expected 0 parameters but got 1 (when running $executeRaw`...`)

olfal opened this issue Β· comments

Hey πŸ‘‹

I'm trying to run this simple statement, but I get a panic crash.

  const newPassword = 'ElitePassword';

  await prisma.$executeRaw`ALTER USER myUser WITH PASSWORD '${newPassword}'`;

Just in case, I've also tried without quoting the newPassword variable, but I get

Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error at or near ""$1""`

Finally, I can work around this by using the unsafe/deprecated version below, but I thought I'd let you know anyway, since this panic crash does not sound right.

prisma.executeRaw(`ALTER USER myUser WITH PASSWORD '${newPassword}'`)

I'm using Prisma with PostgreSQL 12, if that helps.

Here is the full crash report from the error prompt:

Hi Prisma Team! My Prisma Client just crashed. This is the report:

Versions

Name Version
Node v14.15.0
OS darwin
Prisma Client 2.11.0

Logs

  prisma-client {
  prisma-client   engineConfig: {
  prisma-client     cwd: '/Users/olfal/Projects/test/packages/database/prisma',
  prisma-client     enableDebugLogs: false,
  prisma-client     enableEngineDebugMode: undefined,
  prisma-client     datamodelPath: '/Users/olfal/Projects/test/node_modules/.prisma/client/schema.prisma',
  prisma-client     prismaPath: undefined,
  prisma-client     engineEndpoint: undefined,
  prisma-client     generator: {
  prisma-client       name: 'client',
  prisma-client       provider: 'prisma-client-js',
  prisma-client       output: '/Users/olfal/Projects/test/node_modules/@prisma/client',
  prisma-client       binaryTargets: [Array],
  prisma-client       previewFeatures: [],
  prisma-client       config: {}
  prisma-client     },
  prisma-client     showColors: false,
  prisma-client     logLevel: undefined,
  prisma-client     logQueries: undefined,
  prisma-client     flags: [],
  prisma-client     clientVersion: '2.11.0',
  prisma-client     enableExperimental: [],
  prisma-client     useUds: undefined
  prisma-client   }
  prisma-client }  
  plusX Execution permissions of /Users/olfal/Projects/test/node_modules/.prisma/client/query-engine-darwin are fine  
  prisma-client prisma.$executeRaw(ALTER USER myUser WITH PASSWORD '$1';, ["ElitePassword"])  
  prisma-client Prisma Client call:  
  plusX Execution permissions of /Users/olfal/Projects/test/node_modules/.prisma/client/query-engine-darwin are fine  
  plusX Execution permissions of /Users/olfal/Projects/test/node_modules/.prisma/client/query-engine-darwin are fine  
  plusX Execution permissions of /Users/olfal/Projects/test/node_modules/.prisma/client/query-engine-darwin are fine  
  plusX Execution permissions of /Users/olfal/Projects/test/node_modules/.prisma/client/query-engine-darwin are fine  

TLDR

USE

  • NB This is unsafe
+ await prisma.$executeRaw(`ALTER USER prisma WITH PASSWORD '${password}'`)
- await prisma.$executeRaw`ALTER USER prisma WITH PASSWORD '${password}'`
- await prisma.$executeRaw(`ALTER USER prisma WITH PASSWORD $1`, newPassword)

Why

The following does not work as when using prisma.$executeRaw`` it is converted to a PREPARE statement i.e ${password} is converted to $1 so you should use prisma.$executeRaw(``)

await prisma.$executeRaw`ALTER USER prisma WITH PASSWORD '${password}'`

This produces the following query which is not valid SQL as PREPARE does not support ALTER (see)

PREPARE somthing (text) AS
	ALTER USER prisma WITH PASSWORD $1  
EXECUTE somthing('prisma');

If you use the following it will work

const password = "prisma"
await prisma.$executeRaw(`ALTER USER prisma WITH PASSWORD '${password}'`)

as the following is generated

ALTER USER prisma WITH PASSWORD 'prisma'

Hey @williamluke4, thanks for your explanation. This is what we are using at the moment, but we were hoping for a safer version :) We will stick with that.

Happy new year!