I have been searching around for an answer for this but haven't found anything close enough to what I was looking for.
I have two tables:
CREATE TABLE skill_tree (
ID SERIAL PRIMARY KEY,
NAME TEXT NOT NULL,
DESCRIPTION TEXT NOT NULL
);
and
CREATE TABLE skill (
ID SERIAL PRIMARY KEY,
NAME TEXT NOT NULL,
DESCRIPTION TEXT NOT NULL,
DURATION INTEGER NOT NULL,
COOLDOWN INTEGER NOT NULL,
SKILL_TREE_ID SERIAL REFERENCES skill_tree(id)
);
I am trying to return JSON from my postgres db in such a way that it is structured like so:
[{
"id": 1,
"name": "skill tree 1",
"description": "skill tree description",
"skills": [{
"id": 1,
"name": "skill 1",
"description": "skill 1 desc",
"duration": 10,
"cooldown": 20
}, {
"id": 2,
"name": "skill 2",
"description": "skill 2 desc",
"duration": 20,
"cooldown": 30
}]
}]
I was able to get something similar from here [PostgreSQL and nodejs/pg, return nested JSON but wasn't able to retrieve anything more than the skill's name.
SKILL_TREE_ID
column can not be a serial. – Clodoaldo Neto Jul 19 at 12:47