5 ms·
Is there a canonical ORM to use in Go, or would raw SQL be preferred?
by copperx 5y ago
Is there a canonical ORM to use in Go, or would raw SQL be preferred?
- korginator 5y agoThere are ORMs available for Golang, but my experience has been better with packages like sqlx [1] or dat [2]. We've since been using SQLX for pretty much all DBMS related work, and regret nothing. In my experience SQLX gave us the right balance between abstraction and control. [1] http://jmoiron.github.io/sqlx/ http://jmoiron.github.io/sqlx/ [2] https://github.com/mgutz/dat https://github.com/mgutz/dat
- grey-area 5y agoNot really no, the lack of generics has hampered this as you can't easily return slices of arbitrary objects from an ORM so existing ORMs are pretty ugly. One way round this at present is code generation. From your comment I think you're talking about a query builder/executor though, which is a specific part of an ORM, they're pretty simple to build if that is your thing or there are a few examples of that out there. You're really just building up an sql string, storing params, adding a few helpers for things like joins and then executing. I personally use a query generator to generate consistent queries, and generated code per resource to create models from results.