# go-gorm/gorm

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/go-gorm-gorm).**

39,602 stars · 4,134 forks · Go · mit

## Links

- GitHub: https://github.com/go-gorm/gorm
- Homepage: https://gorm.io
- awesome-repositories: https://awesome-repositories.com/repository/go-gorm-gorm.md

## Topics

`go` `golang` `gorm` `orm` `web`

## Description

GORM is a developer-focused object-relational mapping library for Go that provides a comprehensive data persistence framework. It serves as a database access layer, allowing developers to map application structures to database tables and perform CRUD operations using a fluent, type-safe query builder instead of writing raw SQL.

The library distinguishes itself through its association-aware persistence, which automatically tracks and synchronizes complex entity relationships during database operations. It utilizes a driver-agnostic interface to maintain consistent behavior across various storage engines and employs a reflection-based system to map programming language types to database schemas. Developers can further customize behavior using a callback-based hook system that executes logic at specific points in the operation lifecycle.

Beyond core mapping, the project provides robust support for transaction management, connection pooling, and automated schema migrations. It handles complex relational modeling, including one-to-one, one-to-many, and many-to-many associations, while offering advanced features like eager loading, soft deletes, and conflict resolution strategies for upsert operations.

The framework is designed for integration into Go applications, providing a unified interface for managing database connectivity and transactional integrity.

## Tags

### Data & Databases

- [Database Transactions](https://awesome-repositories.com/f/data-databases/database-transactions.md) — Provides a structured API for executing atomic database operations to ensure data consistency and integrity. ([source](https://gorm.io/docs/transactions.html))
- [Object-Relational Mappers](https://awesome-repositories.com/f/data-databases/object-relational-mappers.md) — // Get all recordsresult := db.Find(&users)// SELECT * FROM users;result.RowsAffected // returns found records count, equals `len(users)`result.Error // returns error ([source](https://gorm.io/docs/query.html))
- [Object-Relational Mapping](https://awesome-repositories.com/f/data-databases/object-relational-mapping.md) — Manages complex object relationships by automatically tracking and synchronizing linked records during create, update, and delete operations.
- [Query Builders](https://awesome-repositories.com/f/data-databases/query-builders.md) — A fluent interface for constructing complex SQL statements programmatically while maintaining type safety and preventing common injection vulnerabilities.
- [Database Abstraction Layers](https://awesome-repositories.com/f/data-databases/database-abstraction-layers.md) — Provides a unified abstraction over various database dialects to ensure consistent query execution across different underlying storage engines.
- [Database Transaction Management](https://awesome-repositories.com/f/data-databases/database-transaction-management.md) — GORM perform write (create/update/delete) operations run inside a transaction to ensure data consistency, you can disable it during initialization if it is not required, you will gain about 30%+ performance improvement a ([source](https://gorm.io/docs/transactions.html))
- [Batch Data Processing](https://awesome-repositories.com/f/data-databases/batch-data-processing.md) — To efficiently insert large number of records, pass a slice to the `Create` method. GORM will generate a single SQL statement to insert all the data and backfill primary key values, hook methods will be invoked too. It w ([source](https://gorm.io/docs/create.html))
- [Connection Managers](https://awesome-repositories.com/f/data-databases/connection-managers.md) — Database connection management establishes secure links to external storage systems by initializing drivers with connection strings and configuration settings for reliable communication. ([source](https://gorm.io/docs/connecting_to_the_database.html))
- [Object-Relational Mapping Associations](https://awesome-repositories.com/f/data-databases/object-relational-mapping-associations.md) — GORM automates the saving of associations and their references when creating or updating records, using an upsert technique that primarily updates foreign key references for existing associations. ### Auto-Saving Associa ([source](https://gorm.io/docs/associations.html))
- [Persistence Frameworks](https://awesome-repositories.com/f/data-databases/persistence-frameworks.md) — A structured environment for defining database schemas as code and automating the synchronization of application state with storage.
- [Query Condition Builders](https://awesome-repositories.com/f/data-databases/query-condition-builders.md) — ### String Conditions // Get first matched recorddb.Where("name = ?", "jinzhu").First(&user)// SELECT * FROM users WHERE name = 'jinzhu' ORDER BY id LIMIT 1;// Get all matched recordsdb.Where("name <> ?", "jinzhu").Find( ([source](https://gorm.io/docs/query.html))
- [Transaction Management](https://awesome-repositories.com/f/data-databases/transaction-management.md) — Wraps database operations within atomic units of work to maintain data integrity and ensure consistent state across multiple queries.
- [Transaction Managers](https://awesome-repositories.com/f/data-databases/transaction-managers.md) — Ensuring data integrity by grouping multiple database operations into atomic units that either succeed or fail together.
- [Database Access Layers](https://awesome-repositories.com/f/data-databases/database-access-layers.md) — A collection of tools that manage connections, transaction lifecycles, and query execution across various relational database management systems.
- [Database Connection Pools](https://awesome-repositories.com/f/data-databases/database-connection-pools.md) — Connection pool management optimizes database performance by controlling active and idle connection counts and setting expiration limits for efficient resource usage. ([source](https://gorm.io/docs/connecting_to_the_database.html))
- [Eager Loading Strategies](https://awesome-repositories.com/f/data-databases/eager-loading-strategies.md) — GORM automates the saving of associations and their references when creating or updating records, using an upsert technique that primarily updates foreign key references for existing associations. ### Auto-Saving Associa ([source](https://gorm.io/docs/associations.html))
- [Schema Modelers](https://awesome-repositories.com/f/data-databases/schema-modelers.md) — Database schema modeling allows defining application objects that map to database tables, supporting custom data types, null-value handling, and persistent storage structures. ([source](https://gorm.io/docs/models.html))
- [Single Record Retrievers](https://awesome-repositories.com/f/data-databases/single-record-retrievers.md) — GORM provides `First`, `Take`, `Last` methods to retrieve a single object from the database, it adds `LIMIT 1` condition when querying the database, and it will return the error `ErrRecordNotFound` if no record is found. ([source](https://gorm.io/docs/query.html))
- [Migration Tools](https://awesome-repositories.com/f/data-databases/migration-tools.md) — Synchronizing application data structures with database table schemas to ensure consistent and reliable storage across different environments.
- [Schema Mapping Tools](https://awesome-repositories.com/f/data-databases/schema-mapping-tools.md) — Uses runtime type inspection to automatically map programming language structures to database tables and manage field-level data persistence.
- [Soft Deletion Mechanisms](https://awesome-repositories.com/f/data-databases/soft-deletion-mechanisms.md) — If your model includes a `gorm.DeletedAt` field (which is included in `gorm.Model`), it will get soft delete ability automatically! When calling `Delete`, the record WON’T be removed from the database, but GORM will set ([source](https://gorm.io/docs/delete.html))
- [Upsert Strategies](https://awesome-repositories.com/f/data-databases/upsert-strategies.md) — GORM provides compatible Upsert support for different databases import "gorm.io/gorm/clause"// Do nothing on conflictdb.Clauses(clause.OnConflict{DoNothing: true}).Create(&user)// Update columns to default value on `id` ([source](https://gorm.io/docs/create.html))
- [Connection Pools](https://awesome-repositories.com/f/data-databases/connection-pools.md) — Managing a collection of reusable database connections to improve application performance and resource efficiency under high traffic loads.
- [Data Modeling Tools](https://awesome-repositories.com/f/data-databases/data-modeling-tools.md) — Defining complex relationships between data entities such as one-to-one, one-to-many, and many-to-many associations within an application.
- [Database Deletion Utilities](https://awesome-repositories.com/f/data-databases/database-deletion-utilities.md) — When deleting a record, the deleted value needs to have primary key or it will trigger a Batch Delete, for example: ### Generics API ctx := context.Background()// Delete by IDerr := gorm.GEmail.Where("id = ?", 10).Delete ([source](https://gorm.io/docs/delete.html))
- [Database Lifecycle Hooks](https://awesome-repositories.com/f/data-databases/database-lifecycle-hooks.md) — GORM allows user defined hooks to be implemented for `BeforeSave`, `BeforeCreate`, `AfterSave`, `AfterCreate`. These hook method will be called when creating a record, refer Hooks for details on the lifecycle func (u *Us ([source](https://gorm.io/docs/create.html))
- [Lifecycle Hooks](https://awesome-repositories.com/f/data-databases/lifecycle-hooks.md) — Executes user-defined logic at specific points in the database operation lifecycle to enable custom data validation and transformation.
- [Relational Join Mappers](https://awesome-repositories.com/f/data-databases/relational-join-mappers.md) — Specify Joins conditions type result struct { Name string Email string}db.Model(&User{}).Select("users.name, emails.email").Joins("left join emails on emails.user_id = users.id").Scan(&result{})// SELECT users.name, emai ([source](https://gorm.io/docs/query.html))
