Database
Thirteenth chapter of the "Fastify with TypeScript" series. Our users have lived in memory since chapter 5 and vanish at every restart. Time to give them a real home in PostgreSQL, and to organize the code around it with a repository and a service.
A PostgreSQL to work with
The quickest way to get a database is Docker:
docker run --name fastify-pg -e POSTGRES_PASSWORD = postgres -e POSTGRES_DB = app -p 5432:5432 -d postgres:16
Enter fullscreen mode
Exit fullscreen mode
That matches the DATABASE_URL we put in .env back in chapter 4 ( postgres://postgres:postgres@localhost:5432/app ).…