7 ms·
Generate Go model from database design
- duythinht 6y agohttps://www.dbml.org https://www.dbml.org is awesome, so I have wrote a tool, which parse DBML from both local file or from dbdiagram.io to go struct model.
- Shelnutt2 6y agoI've never heard of dbml before, seems like its been out for about a year. I'm always interested in managing schemas in a db-agnostic fashion. Seems like overtime everything always devolves into db specific schemas (spatial indexes, new datatypes like JSON, etc). I'll read into this and add it to my list to watch. Thanks for sharing this and your work.
- davelondon 6y agoHey you're using my github.com/dave/jennifer package for the code generation. Glad it's helpful!
- duythinht 6y agoIt's an awesome package for generate go code :)
- cybrexalpha 6y agoWhat is it with Go's love of code generation? Everything from protocol implementations to database connections seems to generate a large wad of Go code. Is it just to workaround the lack of Generics?
- zippoxer 6y agoI think it doesn't hurt that most if not all of the packages needed for code generation are built into the language's standard library.
- bagol 6y agoI think it's. Usually, compiler generates each concrete implementation for generic. But in go, that's programmer's job. Maybe it's trade off for language's simplicity.
- erik_seaberg 6y agoThis is an opportunity to use a higher-level DRY language to drive the code generator, and treat Go like assembly.
- loopz 6y agoDunno, but would guess this is consultancy-driven. Nobody would generate code they need to maintain afterwards. In the example of DB schema though, could be a way to avoid ORM but still import schema into code. Code generation is not all barf. Generics are being planned for golang.
- _bxg1 6y agoI don't know why people don't do more of this sort of thing. Keeping models aligned between DB/API/UI/whatever else is a laborious and error-prone process. It's a perfect candidate for a DRY solution.