← All open source projects

GORM

go-gorm/gorm

GORM is an ORM library for Go with associations, hooks, transactions, and an extensible model.

Forks 4,154
Author go-gorm
Language Go
License MIT
Synced 2026-06-27

What It Is

GORM is an ORM library for Go. It helps describe models, relationships, and queries in Go code without completely giving up SQL capabilities.

The project focuses on developer convenience: associations, hooks, preloading, transactions, batch inserts, SQL Builder, upsert, and modes such as DryRun are available in one tool.

It is notable in the Go ecosystem because the language often encourages explicit code, while GORM offers a higher-level data model.

What Is Inside

GORM supports Has One, Has Many, Belongs To, Many To Many, polymorphism, and single-table inheritance. That covers many common domain models.

Hooks before and after create, save, update, delete, and find let teams attach business rules to the model lifecycle.

Transactions, nested transactions, Save Point, RollbackTo, Context support, prepared statements, and batch operations make the library useful beyond small CRUD pages.

How People Use It

GORM is common in services with repeated table work: users, orders, settings, payment records, event logs, and related entities.

The library helps teams move quickly because common queries and relationships are shorter to express. For complex places, SQL expressions and optimizer hints remain available.

The limitation is that ORM convenience can hide query cost. Without attention to preloading, indexes, and database round trips, clear-looking code can become slow.

Model Shape

The neutral example shows what GORM usually describes: a model, its relationship, and an explicit foreign key.

Model And Relation

The example shows the structure usually described in GORM: a user, related orders, and a foreign key.

Language: Plain text
type User struct {
    ID     uint
    Name   string
    Orders []Order
}

type Order struct {
    ID     uint
    UserID uint
    Total  int64
}

Strengths And Limits

GORM’s strength is its broad feature set for real applications: associations, transactions, batching, multiple-database extensions, and metrics integrations.

The weak point is the risk of magic. The more complex the domain model, the more important it is to inspect generated SQL and query plans.

GORM fits Go teams that want development speed and a clean data model. For performance-critical sections, handwritten SQL can still be the better choice.