Re: Package mapping Go structs to sql.DB tables

1,196 views
Skip to first unread message

Kamil Kisiel

unread,
Nov 6, 2012, 1:10:17 PM11/6/12
to golan...@googlegroups.com
The one I'm aware of is called gorp: https://github.com/coopernurse/gorp

As for whether it's a good idea... personally I've just ended up using raw SQL queries. I find the amount of "extra typing" is negligible versus the time spent debugging the idiosyncrasies of such frameworks. In the past I've found they're' very much a 90% solution, and it's that last 10% that ends up being a huge pain.
If you have a half-decent test-suite that checks all your queries against your database it's not hard to find the places where you need to update the code to support your new database schema.
On Tuesday, November 6, 2012 6:31:04 AM UTC-8, Accipiter Nisus wrote:
I am considering creating a package to ease up coding when you have Go structs mirroring the structure of your database tables.

An example of usage would be something like this: http://play.golang.org/p/of21sOGPJf

Why:
To avoid having to edit many places (the SELECT, INSERT and UPDATE queries, db table, struct, etc.) every time a field is added/changed/removed from a table
To decrease the amount of typing needed

So, what I wonder is:
1) Is there any similar package out there already?
2) Is it a bad idea to user reflection is such a manner? (limitations, performance, some other reason) 
3) What would be a better approach than the one in the example?

Accipiter Nisus

unread,
Nov 6, 2012, 3:04:57 PM11/6/12
to golan...@googlegroups.com
That gorp-package looks very similar to what I was considering. Thanks for the link!

As to the usage, I agree that it will probably only be truly useful when you never need to step outside the framework, when the db just becomes a simple storage.
But yes, I've come to the conclusion that the time it takes to create such a package far exceeds the time saved from not having to edit my queries.
... so manually written queries it will be 

Thanks for the input!
Reply all
Reply to author
Forward
0 new messages