I recently saw a job opening where they wanted a Nodejs ,TypeORM and GraphQL developer So I decided now would be a good time to brush up on those skills
Throw back to 3 years a go when Ben Awad was the predominant react influencer on YouTube when he dropped this absolute banger of an intermediate full-stack tutorial
But before starting with that I went back to do a Postgres refresher and tried out a freecodecamp video
In the video they ha a sample movies database which I decided to build an app around as practice and expose a GraphQL API of it
When you already have an existing database you can use the TypeORM option synchronize: false,
typescript
1import{ DataSource }from"typeorm"
2
3exportconst AppDataSource =newDataSource({
4 type:"postgres",
5 host:"localhost",
6 port:5432,
7 username:"postgres",
8 password:"postgres",
9 database:"dvdrental",
10 synchronize:false,
11 migrations:["src/migrations"],
12 entities:["src/entities/*.entity.ts"],
13})
The issue I immediately ran into was how to use the column types database already as to generate TypeORM schemas manually There a was a Postgres query to return a table's column types
sql
1SELECT table_name,
2(SELECT string_agg(column_name,', ')
3FROM information_schema.columns
4WHERE table_schema = t.table_schema
5AND table_name = t.table_name)AScolumns,
6(SELECT string_agg(data_type,', ')
7FROM information_schema.columns
8WHERE table_schema = t.table_schema
9AND table_name = t.table_name)AS column_types
10FROM information_schema.tables t
11WHERE table_schema ='public'
But it wasn't very clear on Enum types and other types like that for example the film table had rating column that was an Enum type
You could get the Enum values using a distinct select
sql
1SELECTDISTINCT rating FROM film
But this didn't feel scalable so I built a simple Postgres GUI as a challenge to view the columns and their types and feed that info into an LLM to get a schema.
Postbase , Am bad at naming things but in It's basics
When loaded up the /pg route , This snippet will run and fetch all the databases running on your Postgres server
32// console.log(" ====== next file path ======",next_file_path);
33 updatedText =
34(awaitgetTextFromFileWithImports(next_file_path, updatedText, dbName))??"";// Make the process recursive
35}
36// console.log("===== count ======",count);
37return updatedText;
38}catch(error){
39console.log("====== error in readTextFromFileWithImport === ", error);
40return;
41}
42}
A helper to trim out any markdown code blocks that gemini was adding randomnly in it's responses like this 
And with that we have a basic PostgresSQL GUI hat generates TypeORM and TypeGraphQl classes for us , I feel like this will come in handy soon 😏 . feel free to play with it and discover new patterns
Next step is using something like wails or tauri or electron to package it into a binary for better DX