Hi I was never dealing with database programming +go so am after some advice. I have a database with few tables, some of them are related using foreign keys. Not smth complex, but I thought there has to be some auto solution that shall let me create corresponding go structs to use with let's say dbr package. But for some reason I spent like a day looking for it and really didn't find anything. The only thing close to what I was looking for seemed knq/xo package but it shows error
error: Error 1109: Unknown table 'parameters' in information_schema
When I try using it.
I thought this task is common but somehow I stucked with it.
评论:
Tikiatua:
twek:Take a look at sqlboiler https://github.com/vattle/sqlboiler
sergeykurt:This one, love it, I only wish it worked with Microsoft SQL as I'm forced to use that at work
twek:Take a look on this PR - MS SQL engine support #119
chmikes:Thanks for this. I will be watching :))
lunnyxiao:What you describe is called an ORM. It maps programming language specific data structures with database tables. Xorm looks nice. Here is its documentation. http://xorm.io/docs/. There are many ORM with many different functionalities and properties. Xorm has nice functionalities. One interesting property of ORM is that it can be used with many different databases. So you can develop and test your code with SQLight and use MySQL or PostgreSQL in production.
I didn't use it yet, but I plan to use it once I start developping the database backend of my software.
jimmeyotoole:maybe you can try github.com/go-xorm/cmd
fraenky8:Whilst there are orm for go as people are suggesting, I recommend sqlx which just had really nice helpers for saving and getting from a usual dB. It hooks right into regular SQL go package too
nkumar15:Maybe this is useful for you: https://github.com/fraenky8/tables-to-go
knq:I think you could give a try to https://upper.io/db.v3/
Its a nice library to write Data Access Layer logic without writing much of Sql queries explicitly.
xo
should work fine with most MySQL databases. Are you using a old MySQL version? If you could provide more information about the database version you're using, I can help find out what the issue is.
