We should highlight that using prisma.raw() with parameters is not secure and recommend using prisma.raw``
See original GitHub issueProblem
Users are using prisma.raw() like
const data = await prisma.raw(
`SELECT * FROM "ProviderItemAttribute" WHERE "provider_item" = ${root.id} AND "user" = ${auth.user.id} limit 1;`,
);
This example is using prisma.raw() the pure text version so there is no security around parameters.
Only raw`` is secure because it’s using https://github.com/blakeembrey/sql-template-tag
Solution
In this case it would be recommended to do
const data = await prisma.raw`
SELECT * FROM "ProviderItemAttribute" WHERE "provider_item" = ${root.id} AND "user" = ${auth.user.id} limit 1;
`;
This should be highlighted in the docs (and examples?)
We also can think about how to warn users that are using prisma.raw() or even disable it under a flag?
Note prisma.raw`` parameters do not work as of today with PostgreSQL see https://github.com/prisma/prisma-client-js/issues/595
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:13 (10 by maintainers)
Top Results From Across the Web
Raw database access (Reference) - Prisma
Learn how you can send raw SQL and MongoDB queries to your database using the raw() methods from the Prisma Client API.
Read more >Prism
Prism is a lightweight, extensible syntax highlighter, built with modern web standards in mind. It's used in millions of websites, including some of...
Read more >A Prisma ORM Review - HackerNoon
Prisma ORM is a good choice for your project. ... You have to define your models in a separate file and use specific...
Read more >The best TypeScript ORMs - LogRocket Blog
Should we use ORMs in our TypeScript codebases? Picking the best TypeScript ORMs. Prisma; TypeORM; MikroORM; Sequelize; Objection.js. How to ...
Read more >How To Build a REST API with Prisma and PostgreSQL
Prisma is an open source database toolkit. In this tutorial, you will build a REST API for a small blogging application in TypeScript...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

IMO, this is not just a docs issue – highlighting it in the docs is NOT enough. In fact, the current docs are long outdated, which shows how many users actually read them before using a feature. It’s not enough.
@alexvilchis Can you please open a new issue with a reproduction for that? That should not happen