* Executes a raw query provided through a safe tag function * @see https://github.com/prisma/prisma/issues/7142 * * @param query * @param values * @returns
(query: TemplateStringsArray | Sql, ...values: any[])
| 567 | * @returns |
| 568 | */ |
| 569 | $executeRaw(query: TemplateStringsArray | Sql, ...values: any[]) { |
| 570 | return this._createPrismaPromise((transaction) => { |
| 571 | if ((query as TemplateStringsArray).raw !== undefined || (query as Sql).sql !== undefined) { |
| 572 | const [sql, argsMapper] = toSql(query, values) |
| 573 | checkAlter( |
| 574 | this._activeProvider, |
| 575 | sql.text, |
| 576 | sql.values, |
| 577 | Array.isArray(query) ? 'prisma.$executeRaw`<SQL>`' : 'prisma.$executeRaw(sql`<SQL>`)', |
| 578 | ) |
| 579 | return this.$executeRawInternal(transaction, '$executeRaw', sql, argsMapper) |
| 580 | } |
| 581 | |
| 582 | throw new PrismaClientValidationError( |
| 583 | `\`$executeRaw\` is a tag function, please use it like the following: |
| 584 | \`\`\` |
| 585 | const result = await prisma.$executeRaw\`UPDATE User SET cool = \${true} WHERE email = \${'user@email.com'};\` |
| 586 | \`\`\` |
| 587 | |
| 588 | Or read our docs at https://www.prisma.io/docs/concepts/components/prisma-client/raw-database-access#executeraw |
| 589 | `, |
| 590 | { clientVersion: this._clientVersion }, |
| 591 | ) |
| 592 | }) |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * Unsafe counterpart of `$executeRaw` that is susceptible to SQL injections |