Course

What is an ORM?

An is a powerful tool that simplifies the process of working with databases in your code. It acts as a bridge between your application and the database, allowing you to interact with the database using the programming language you're comfortable with, such as JavaScript, instead of writing raw SQL queries.

Think of an ORM as a translator that speaks both the language of your application and the language of your database. It provides a set of methods and abstractions that let you perform database operations, like creating, reading, updating, and deleting records, using familiar JavaScript syntax.

In the upcoming lessons, we'll be focusing on , a popular ORM for Node.js applications. Prisma simplifies database management by:

  • Letting us write simple 'schema' files to generate SQL
  • Giving us javascript methods to query our database
  • Handling relations between tables for us

One of the significant advantages of using an ORM like Prisma is that it eliminates the need to write complex SQL queries manually. Instead, you can use JavaScript objects and methods to interact with your database. For example, to fetch all users from a database table, you might write something like:

to retrieve all records from the "user" table. Prisma takes care of generating the appropriate SQL query behind the scenes.

Example Of Using Prisma:

const users = await prisma.user.findMany({
  select: {
    email: true,
    name: true,
  },
});
SELECT "public"."User"."id", "public"."User"."email",
"public"."User"."name" FROM "public"."User" WHERE 1=1
OFFSET $1
[
  {
    name: "Billy",
    email: "Billy@email.com",
  },
  {
    name: "Elise",
    email: "elise24@gmail.com",
  },
];

0 Comments

"Please login to view comments"

glass-bbok

Join the Conversation!

Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.

Upgrade your account
tick-guideNext Lesson

Setting Up Prisma