4 ms·
You misunderstood the entire article. This is about formatting the data from Postgres. It doesn't change anything about your testing. If you're mocking data, yo
by midev 5y ago
You misunderstood the entire article. This is about formatting the data from Postgres. It doesn't change anything about your testing. If you're mocking data, you mock the JSON instead of raw rows. If you were doing integration tests, nothing changes anyway.
> Also PG returns some JSON but if the object is not exactly what you want to send back you create another object and merge the two
Sure. Literally nothing changes. Just as if you had to assemble a JSON blob from two Postgres queries and merge them.
> Just don't do it, it's a terrible design. It "works" for simple API but for anything serious this is wrong
I think you completely misunderstood the article. Returning a JSON object from a database query is not "wrong", and I've used this pattern with great success. It's so much easier to call a json_agg to turn a subquery into an array, than to try and manually parse out rows yourself in the middle layer.