Data Management Tools
Managing raw SQL can be hard. We use tools to help us.
ORM (Object-Relational Mapping)
Section titled “ORM (Object-Relational Mapping)”An ORM lets you interact with your database using your programming language (like JavaScript) instead of writing raw SQL queries.
- Prisma: Modern ORM for TypeScript and Node.js. Very popular.
- Drizzle: Lightweight and fast ORM.
Example (Prisma Query)
Section titled “Example (Prisma Query)”Instead of SELECT * FROM users, you write:
const users = await prisma.user.findMany();For a deeper guide (schema, queries, raw SQL, and an Express example), see:
Migrations
Section titled “Migrations”Database Migrations are like version control for your database schema. They treat changes to your database structure (like adding a column) as code.
- Helps teams stay in sync.
- Allows you to roll back changes if something breaks.
Prisma Migrations (Typical Workflow)
Section titled “Prisma Migrations (Typical Workflow)”- Edit
schema.prisma - Run a migration to update your database schema
- Prisma generates migration files and updates the client
Caching
Section titled “Caching”Caching stores copies of data in a faster storage (usually RAM) so future requests for that data can be served faster.
- Browser Caching: The browser saves images/css.
- Server Caching: The server saves HTML or API responses.
- Database Caching: Using Redis to store frequent queries.
- Memcached (mentioned): A simple, in-memory cache (key/value). Often used for very fast caching, but with fewer features than Redis.