finds.dev← search

// the find

smallnest/gen

★ 1,441 · Go · Apache-2.0 · updated Apr 2023

Converts a database into gorm structs and RESTful api

gen connects to a MySQL/Postgres/SQLite/MSSQL database, reads the schema, and spits out a complete Go project: GORM structs, DAO CRUD functions, Gin HTTP handlers, Swagger docs, and a Makefile. It's aimed at developers who want a working REST API skeleton from an existing database without writing the boilerplate by hand.

The template system is genuinely flexible — you can export the embedded templates, edit them, and feed them back in, or write a custom .gen script that calls GenerateTableFile in a loop. That's the right escape hatch for when the defaults don't fit. Support for both GORM and SQLX DAOs is a real differentiator; most tools in this space pick one. The generated structs handle nullable columns correctly with sql.NullX or guregu types rather than pretending everything is non-null. The --exec scripting approach, where a template can invoke mkdir, copy, and touch, means you can bolt it into a real project scaffold without forking the tool.

Last commit was April 2023, and it's still targeting GORM v1 (jinzhu/gorm), not GORM v2 (gorm.io/gorm) — the API changed significantly in 2020 and the generated code will need manual fixes before it compiles against anything current. The generated CRUD is purely flat table operations with no support for foreign key relationships, so you get an AlbumID int field with no way to tell the generator to also load the Artist. It uses packr2 for embedding templates, which is abandoned and superseded by Go's built-in embed package — building the tool itself is already friction. The README is auto-generated from its own template system, which is a neat trick until it gets out of sync with reality.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →