ORMs and APIs
Ketan Mayer-Patel
UNC Department of Computer Science
COMP 426: Modern Web Programming (Fall 2026)
Module 4: Backend
Lecture 15
Last lecture, we introduced relational databases.
Recap
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Client
Router
React, etc
Next App
DB Server
Database
Our applications can perform CRUD operations on the database.
C: Create�R: Read
U: Update�D: Delete
We can interact with databases using SQL (structured query language)
SQL (Structured Query Language)
COMP 426: Modern Web Programming (Fall '26)
ORMs and APIs
M4: Backend
L15
script.sql
SELECT singer_id, title, duration
FROM song
WHERE duration > 20;
SQL is a language dedicated to interacting with databases.
The Problem
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
With SQL...
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Client
Router
React, etc
Next App
DB Server
Database
Raw SQL
SELECT * FROM users;
Raw string
“...”
SQL is a language dedicated to interacting with databases.
We need a tool to be able to interact with SQL databases from within our TypeScript code in a manner that is native to our programming language...
The Problem
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Object Relational Mappers (ORMs)
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
With SQL...
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Client
Router
React, etc
Next App
DB Server
Database
Raw SQL
SELECT * FROM users;
Raw string
“...”
With an ORM
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Client
Router
React, etc
Next App
DB Server
Database
Raw SQL
Raw string
ORM
TS func
TS object
Drizzle
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Client
Router
React, etc
Next App
DB Server
Database
C: Create�R: Read
U: Update�D: Delete
Just like with regular servers, databases are accessible on the network.
We pass our database URL into Drizzle to access our database.
const db = drizzle(“postgresql://user:password@host:port/dbname”);
Our applications can perform CRUD operations on the database using Drizzle.
Drizzle
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Next App
Just like with regular servers, databases are accessible on the network.
We pass our database URL into Drizzle to access our database.
const db = drizzle(“postgresql://user:password@host:port/dbname”);
There is a SEVERE problem here with our approach.
Discuss with the people around you - can you find it?�(Hint in 2 minutes)
Client
Router
React, etc
Next App
DB Server
Database
C: Create�R: Read
U: Update�D: Delete
Our applications can perform CRUD operations on the database using Drizzle.
Drizzle
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Next App
Just like with regular servers, databases are accessible on the network.
We pass our database URL into Drizzle to access our database.
const db = drizzle(“postgresql://user:password@host:port/dbname”);
There is a SEVERE problem here with our approach.
Discuss with the people around you - can you find it?�(Hint in 2 minutes)
Think security!
Client
Router
React, etc
Next App
DB Server
Database
C: Create�R: Read
U: Update�D: Delete
Our applications can perform CRUD operations on the database using Drizzle.
Drizzle
!
Attendance
Check!
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
Router
React, etc
Next App
Drizzle
M4: Backend
L15
Vercel (or Dev) Server
Next Server Functionality
Review: Loading a Website
Data Server
Client
The client requests a page on our website.
The server responds with HTML, CSS, JS
The JS runs, loading all functionality (including React, our Router, and Drizzle).
Database
Drizzle connects to the database with the provided database URL.
… where is that database URL stored?
In the JS files received by the client.
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
Router
React, etc
Next App
Drizzle
M4: Backend
L15
Vercel (or Dev) Server
Next Server Functionality
Review: Loading a Website
Data Server
Client
The client requests a page on our website.
The server responds with HTML, CSS, JS
The JS runs, loading all functionality (including React, our Router, and Drizzle).
Database
Drizzle connects to the database with the provided database URL.
… where is that database URL stored?
In the JS files received by the client.
The direct URL to access our database is part of the JS bundle the client receives.
Any malicious user can look through the JS received from our site and gain unauthorized access to our database!
We need to modify our setup so that we protect direct access to our database.
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
Router
React, etc
Next App
Drizzle
M4: Backend
L15
Vercel (or Dev) Server
Next Server Functionality
Data Server
Client
Database
Remember that Next.js is capable of running functionality on the server.
This powers server-side rendering (SSR).
What if our server can handle database operations?
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
Router
React, etc
Next App
Drizzle
M4: Backend
L15
Vercel (or Dev) Server
Next Server Functionality
Data Server
Client
Database
What if our server can handle database operations?
Drizzle
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
Router
React, etc
Next App
M4: Backend
L15
Vercel (or Dev) Server
Next Server Functionality
Data Server
Client
Database
Drizzle
The server is responsible for interacting with the database and is given access to the database URL.
This database URL is then not given as part of the client JS bundle, ensuring it never gets leaked to malicious users.
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
Router
React, etc
Next App
M4: Backend
L15
Vercel (or Dev) Server
Next Server Functionality
Data Server
Client
Database
Drizzle
Now, we just need to add a way for the client to request database operations…
APIs!
Our client code can make HTTP requests to the server and the server will respond to these requests by running some TS code.
The server performs CRUD operations on the database.
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
Router
React, etc
Next App
M4: Backend
L15
Vercel (or Dev) Server
Next Server Functionality
Data Server
Client
Database
Drizzle
Our client code can make HTTP requests to the server and the server will respond to these requests by running some TS code.
The server performs CRUD operations on the database.
We can supply a method with our HTTP request to specify information about the type of operation we want to perform.��GET, POST, PUT, DELETE
C: Create�R: Read
U: Update�D: Delete
(READ)
(CREATE)
(UPDATE)
(DELETE)
GET /api/pokemon
GET /api/wordle/random-word
We have been doing this already - just, we have interacted with external servers using fetch.
+ more
We can now define what the server does and what it responds with ourselves.
Music API Example
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
Router
React, etc
Next App
M4: Backend
L15
Vercel (or Dev) Server
Next Server Functionality
Data Server
Client
Database
Drizzle
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Vercel (or Dev) Server
Next Server Functionality
Data Server
Client
Database
Drizzle
Code running on the client side is typically called the “frontend”
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Vercel (or Dev) Server
Data Server
Client
Database
Code running on the client side is typically called the “frontend”
Code running on the server side is typically called the “backend”
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Vercel (or Dev) Server
Data Server
Client
Code running on the client side is typically called the “frontend”
Code running on the server side is typically called the “backend”
Databases + other svcs the backend relies on is typically called the “data layer”
The Three-Tier Architecture
You will be writing server-side code in the next assignment.
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
Router
React, etc
Next App
M4: Backend
L15
Vercel (or Dev) Server
Next Server Functionality
Data Server
Client
Database
Drizzle
How do we actually set up this data server to hold our database?
BaaS Providers
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
Popular BaaS Providers
M4: Backend
L15
Intro to Supabase
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15
Let’s See Supabase in Action
ORMs and APIs
COMP 426: Modern Web Programming (Fall '26)
M4: Backend
L15