Gnorm vs ...
GORM is a Go ORM.
- GORM is code-first. It generates the database from your code, using
GORM-specific techniques that obscure what’s really happening in the DB.
- Gnorm is database-first. You generate your database using the first class tools for your DB (sql, pgAdmin, whatever).
- GORM is only for go.
- Gnorm can generate code for any language, or even docs or protobufs.
- GORM is a framework (it calls you) that uses a ton of reflection, special tags, and naming conventions to create behaviors. This makes it run slow, and makes reading and debugging the code difficult.
- Gnorm generates simple, easy-to-understand boilerplate that would be tedious and error-prone to write, but offers the best speed and least complexity.
SqlBoiler is a database-first fluent-api generator for Go.
- SqlBoiler only outputs Go code.
- Gnorm outputs any langauge, even non-code things, like protobufs or docs.
- SqlBoiler produces a fluent API style of code that is non-idiomatic for Go.
- Gnorm can generate idiomatic go code.
- SqlBoiler requires magic strings for queries (e.g. Where(“age > ?”, 30), which offer no type safety or compile-time checks. If you change the name or type of a column, that code won’t fail until it’s triggered by a test or in production.
- Gnorm can generate type-safe queries that ensure that if a column’s type or name change, your code will fail to compile.
XO is a code generator focused on producing Go code for your database.
- XO is mainly aimed at producing Go code and thus has a lot of assumptions built in (like what types you want to use to represent specific DB types).
- Gnorm doesn’t make any assumptions about what you’re outputting, so you’re never “swimming upstream”.
- XO only produces code in a single directory with specifically named files. If you have a big DB schema (or even if you don’t), this limits you to long ugly names in order to namespace things, and prevents many more advanced layouts.
- Gnorm lets you control the directory and filename generated for each schema, table, and custom type.
- XO has a mode that will output code that mimics a specific query.
- Gnorm doesn’t have this, but you can generally generate code to support almost any query, and then just write the query yourself.
Many of these tools support more databases that Gnorm at this time (gnorm only
supports Postgres and MySQL). All of these tools are fine works of
craftsmanship and if they fit your need, you should absolutely use them.