4 ms·
I also try to avoid ORM's but ditching them makes mapping to struct/objects cumbersome. How you deal with mapping joins in Go and node.js?
by jennoo 7y ago
I also try to avoid ORM's but ditching them makes mapping to struct/objects cumbersome. How you deal with mapping joins in Go and node.js?
- davismwfl 7y agoI find having results in object form for CRUD API's most of the time is unnecessary, and this is a lot of what happens and people use ORM's for. When I do need the data in object form I use what is probably an unpopular method for a lot of people, that is I build a serialize/deserialize solution (or use one already built). It isn't hard in either node.js or Go. It can add some fragility into the codebase, however, depending how it is implemented. Frankly though, I like this because essentially this is what an ORM would do too, just an ORM would be trying to build the query, guess on keys, indexes etc and then still serialize and deserialize my data, which again may not be ideal because of generic choices it has to make. Also, a fairly common pattern for CRUD APIs is I do not need to map the returned data into an object ever, I simply need a json object to return. And at least when using postgres I can use jsonb_agg and to_jsonb to help make life really easy. MySQL has similar json functions. When doing updates the submitted json data is used to build the query so there is no need to really have things in native object form. Hopefully that all makes sense.