Chapter 4: ORM

ORM
19:22

Idea

Use object-oriended programming (in particular inheritance) to simplify data manipulation.

Question

What is an ORM?

Definition

It is a programming technique for converting data in a relational database to simulate an object-oriented database.

Examples
19:22

SQL query

ORM (example syntax)

How does it typically work?
19:22

  • One class per table
  • One instance correspond to a record in the database
  • Tables are associated with classes that all inherit from the same base class. These children classes typically contain at least table specific information (e.g. name, primary keys, relationships, field names for typing)
  • The base class implements the methods to generate and execute queries.

Un ORM simple
19:22

Todo app avec un ORM
19:22

Advantages
19:22

  • No need to write SQL queries
    • Better for security
    • Better to manage relationships
  • Type safety
  • Handle migrations

However, using has an ORM has a performance cost.

Using Prisma
19:22

Prisma Quickstart

  • You can use SQLite for your project
  • Read the quickstart, and the documentation page for CRUD and relation queries