next-learn icon indicating copy to clipboard operation
next-learn copied to clipboard

Chapter 6: No Postgress SQL data base available, tutorial bottleneck

Open daninaydenow opened this issue 1 year ago • 4 comments

As stated in the chapter

Create a Postgres database " Next, to set up a database, click Continue to Dashboard and select the Storage tab from your project dashboard. Select Create Database. Depending on when your Vercel account was created, you may see the following options: Postgres (Powered by Neon), Neon, or Supabase. Choose your preferred provider and click Continue. "

The problem is that there is no option for PostgresSQL.

Please either update the tutorial to include a DB from the existing options, or provide some backwards compatible way to use Postgres.

daninaydenow avatar Dec 14 '24 18:12 daninaydenow

In the meantime you can use your own local database instead of using Vercel by using Docker.

docker run -d --name=postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:latest

Then you have to rewrite the code in query/route.ts and seed/route.ts to use another Postgres client instead of the Vercel client. I did so using pg.

pnpm install pg
import { Client } from "pg";

const client = new Client({
    host: "localhost",
    port: 5432,
    user: "postgres",
    password: "postgres",
    database: "postgres",
});

await client.connect();

Then just replace all calls in query/route.ts and seed/route.ts by changing client.sql to client.query and everything should work perfectly fine without requiring a database from Vercel.

tobyguelly avatar Dec 14 '24 20:12 tobyguelly

For anyone else learning on the fly for this change: https://node-postgres.com/features/queries

RyanMG avatar Dec 21 '24 18:12 RyanMG

I selected Neon from the marketplace and was able to proceed with the tutorial (today).

kamalx avatar Dec 24 '24 00:12 kamalx

At the end I decided to run a local Postgres db, to use the opportunity to learn SQL, and Postrgres specifically, as I'll need more DB knowledge anyways, if I am headed in the path of full-stack web dev. This chapter actually made me take a step back and expand my knowledge. I'm closing the issue, and thanks to everyone who replied ❤️

daninaydenow avatar Dec 28 '24 12:12 daninaydenow