I have switched to PostgreSQL for my mobile app backend and trying to figure out best way to store and query data. The thing is that storing the data is best as SQL, but retrieving data would be best as document.
So for example, I have table Items:
+----+--------+------+
| id | title | uuid |
+----+--------+------+
| 1 | Hello | 32 |
| 2 | World | 25 |
| 3 | Tom | 435 |
+----+--------+------+
And then table Records:
+----+---------+----------+
| id | itemId | resource |
+----+---------+----------+
| 1 | 1 | res1 |
| 2 | 1 | res2 |
| 3 | 1 | res3 |
| 4 | 2 | res4 |
+----+---------+----------+
Which is pretty much standard SQL approach. Now what I want to get is this:
{
id: 1,
title: "Hello",
uuid: 32,
records: [
{id: 1, resource: "res1"},
{id: 2, resource: "res2"},
{id: 3, resource: "res3"}
]
}
I think you get the picture. I am fairly new to PostgreSQL and I am sure that in all its awesomeness there will be elegant solution to this. All I could think of was creating view table that I could query, but not sure how exactly build the query for this.