From SQL to ORM and back

Let’s face it, we’ve all been there. We started our career with SQL, found it cumbersome and difficult to remember, had too many DataManager classes around to encapsulate queries and got tired of all that work. Then suddenly we were hit by the light at the end of the tunnel.. an ORM.. in my case Hibernate was love at first sight. No more fussing with SQL dialects, no more Stored Procedures on Oracle, something reusable, write once run on any DB, real java style. And then just sometimes you’d hit a wall where some really crazy query or nested selects weren’t as easy without having to really know every nuance of the library, and even then it sometimes wouldn’t work. And then there was the Heap growing like crazy, garbage collection to tame, too many objects being pulled into memory during a massive select. Of course there was also data mapping, but that was even more xml, no thanks. Then came Ruby on Rails with ActiveRecord and all its beauty and ease. Everything was a breeze. Except it wasn’t and sometimes you’d still need to do some nasty native query. But hey it was nice. Most of the time. Until of course it took more code and workarounds to make AR behave like a very specific native query that just couldn’t be mapped. And maybe it ended up with more code, more loops and more memory than necessary. And don’t even get me started on performance! And so recently (like a couple of years now) I came to know Go. Go is plain but in a subtle way. But database wise it doesn’t come with a lot of extras attached. So I went back to having structs mapped to tables (well not only) and to using plain old native SQL (yes I have the luxury of saying I want Postgres because Heroku or other services will just allow me to). And so everything became sort of “simple” again. Of course there’s more work involved. I have query files that are pure SQL and call them from my code. I need to cycle through results or just assign a query result to an array and all. But.. and this is very important, I have two big wins: 1) I have complete control 2) I have super performant code

The only downside is you need to really know your SQL.. but hey… SQL is something that will never die, just like C and Linux. So learning it is investing in a lifelong skill anyway. Plus the amount of control is simply stunning. No more walls. No more coding around a barrier or lack of implementation in a library. This feels like home. Yep.