API Design in Node.js, v5

PostgreSQL & ORMs

Scott Moss
Netflix
API Design in Node.js, v5

Lesson Description

The "PostgreSQL & ORMs" Lesson is part of the full, API Design in Node.js, v5 course featured in this preview video. Here's what you'd learn in this lesson:

Scott discusses Postgres as a versatile open-source database with features like JSON and geospatial search. He emphasizes using Node.js with Postgres for its ecosystem and ORM support, explaining ORMs provide type safety and help prevent SQL injection.

Preview
Close

Transcript from the "PostgreSQL & ORMs" Lesson

[00:00:00]
>> Speaker 1: PostgreSQL or PSQL, with Node.js, is probably the most popular database in the world depending on who you ask It's definitely the most sought after Technically, SQLite would be the most used database in the world, but people are doing different things with it than with PostgreSQL PostgreSQL has tons of different data types

[00:00:00]
It has JSON arrays, custom types You've got full-text search, GIS (geospatial search), so you can put in longitude and latitude, and it'll triangulate It'll do math on geospatial calculations To be fair, a lot of databases do that too It's pretty good for complex queries if you're into that stuff And it's open-source, which is great - no one really owns it

[00:00:00]
There are so many integrations with PostgreSQL, it's insane SQLAlchemy makes it really good, and the reason I'm mentioning that is because using a database without an ORM (like using Python without SQLAlchemy) just feels bad It has a very strong ecosystem with tons of ORM options and excellent TypeScript support

[00:00:00]
Being able to have typed support for your database is just so good - I would never trade that up What is an ORM Technically, it stands for Object-Relational Mapping, but it's essentially the SDK for your database This is how you interact with your database in your code There are tons of ORMs that support different databases, and they all do it differently

[00:00:00]
I almost never want to call it an ORM again because I don't fully understand "object-relational mapping" - it's simply an SDK for your database Without an ORM, interacting with your database looks like low-level client work with vanilla SQL I'm never doing that If I had to, I would, but then I'd complain about it

[00:00:00]
I'd rather use something like an ORM - type-safe, with super easy functions to use Everything's good to go You don't need to know the underlying SQL It helps with things like potential SQL injection, though honestly, you shouldn't be putting raw SQL queries from users into your database without sanitizing it anyway

[00:00:00]
You could technically use raw SQL with an ORM too and solve the same problems For me, it's mostly about not needing to go deep into SQL You could become a SQL expert and charge millions, but I know just enough to get the job done and refuse to learn more The type safety is just outstanding We'll be using an ORM that makes database interactions super easy and helps us with our schema.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now