I have the power!
July 4, 2018, 10:18 a.m.
If you had been here just a few moments ago you would have seen and heard me yelling that just like He-Man.
Well not really but that is exactly what I felt. So why do I felt like that I had all the power in the world? Because I solved my problem I had which was saving my JSON to database. How? By using ORM or more specifically GORM. It wasn't really the solution I wanted to use at start but fuck it (pardon my french). It's my project and I can do what I want. Whatever.
At this point I'm not sure if I should cry or laugh since using GORM made everything so simple. Only change I had to make to my struct was changing the type of the property in question to postgres.Jsonb. My getAllItems function went from 20 lines to 2 lines and createItem function went from 25 to 9. The create function does have some unneeded extra like creating UUID and logging if errors (unneeded for GORM that is) so it could be done with just one line:
I haven't done delete and update functions yet but I expect them to be as easy as those two, too. I'm just wondering if or when does this decision to use (G)ORM come back and bite me in the ass. It does add that extra layer of abstraction I wanted to avoid but at least I can move forward with the project now.
Edit: Updating records was trickier than I thought but nothing too difficult though. For updating GORM wanted to have the primary key (at least I didn't find a way around it) which I do not send to frontend at all. So first I had to search for the record I want to update just to get the primary key and then assign it to the object created from JSON and then do the update.