Skip to content

vherus/database-orm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Databases - ORM's using Prisma.js

An object-relational mapper provides a layer between relational databases and programming languages without the need to write SQL. It standardizes interfaces, reducing boilerplate while speeding up development time. With the Prisma.js ORM, we can interact with our database by writing Javascript instead of executing SQL.

Learning Objectives

  • Use an ORM to implement a database design.
  • Use an ORM to create data in a database.
  • Follow an iterative development workflow style.

Introduction

SQL is useful but it can be hard to debug and maintain, especially as an application grows in size. There are many ORM's out there for many languages; we'll be using Prisma.js during the Boolean course.

A vital piece of our skillset as software developers is our ability to use documentation to work with a tool we have little to no experience with. Prisma's documentation is comprehensive and easy to navigate, which is why we'll be using it to improve these skills during this module.

Though not required, you may find it useful to read about Prisma's core concepts.

To work with Prisma in our development environments, we require two databases:

  1. The Primary database - this is the one you have designed with your Entity Relationship Diagram and will contain all of your tables and data.
  2. The Shadow database - this is a temporary database that Prisma uses to check that everything works properly before making any changes to the primary database. It's essentially a safety net to protect us from ourselves.

Note: Shadow databases are a concept specific to Prisma, not ORM's in general. In most cases, an ORM will execute migrations as a transaction that can be reversed if anything goes wrong. If you're interested in this subject, here's an example.

Setting up

  1. Create a new database instance in ElephantSQL.
  2. Edit the DATABASE_URL variable in .env, swapping YOUR_DATABASE_URL for the URL of the database you just created. Leave ?schema=prisma at the end.
  3. Create another new instance in ElephantSQL (this will be your Shadow Database).
  4. Edit the SHADOW_DATABASE_URL variable in .env, swapping YOUR_SHADOW_DATABASE_URL for the URL of the shadow database you just created. Leave ?schema=public at the end.
  5. Run npm ci to install the project dependencies.
  6. Run npx prisma migrate reset to execute the existing migration & data seed. Press y when it asks if you're sure.

Instructions

  • Work through each file in the requirements directory in numerical order
  • Follow the full Development Process in the requirement file before moving to the next requirement

Collection of Useful Documentation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published