Using SQL Queries Directly with Prisma and TypeORMs
Explore how to directly write and execute custom SQL queries with Prisma and TypeORM ORMs in Node.js. Understand methods like Prisma's $queryRaw and TypeORM's query and Raw for managing dynamic queries securely. Gain practical skills to enhance database interactions beyond automatic query generation.
We'll cover the following...
Introduction
ORMs are very handy because they write SQL queries behind the scenes. We may sometimes want to write this query ourselves, for one or several reasons. In this lesson, we’ll take a deep dive into how to achieve this with the ORM libraries we’ve discussed so far.
Prisma
The $queryRaw method
This method allows us to write custom SQL queries. In the code given below, we first import the PrismaClient class from which the $queryRaw method is derived. We then make a simple SELECT SQL query to get all the employee records.
Since these custom SQL queries are simply strings, ...