Introduction

gdb chaining operation is simple and flexible, and is the officially recommended database operation method by the GoFrame framework. Chaining operation can be done by using the db.Model method of the database object or the tx.Model method of the transaction object, which returns a chaining operation object *Model based on the specified data table. This object can perform the following methods. The current method list may lag behind the source code; for a detailed method list, please refer to the API documentation: https://pkg.go.dev/github.com/gogf/gf/v2/database/gdb#Model

Partially Unsupported Operations

Below is the support status of the latest version

TypeReplaceSaveInsertIgnoreInsertGetIdLastInsertIdTransactionRowsAffected
mysqlSupportedSupportedSupportedSupportedSupportedSupportedSupported
mariadbSupportedSupportedSupportedSupportedSupportedSupportedSupported
tidbSupportedSupportedSupportedSupportedSupportedSupportedSupported
pgsqlUnsupportedSupportedUnsupportedSupportedSupportedSupportedSupported
mssqlUnsupportedSupportedSupportedSupportedUnsupportedSupportedSupported
sqliteUnsupportedSupportedSupportedSupportedSupportedSupportedSupported
oracleUnsupportedSupportedSupportedSupportedUnsupportedSupportedSupported
dmUnsupportedSupportedSupportedSupportedSupportedSupportedSupported
clickhouseUnsupportedUnsupportedUnsupportedUnsupportedSupportedUnsupportedUnsupported

Documentation

📄️ ORM Model - ModelUsing the ORM tool in the GoFrame framework for chaining operations, focusing on model creation, the use of Model objects, and ways to ensure chaining safety. By using the Model and Raw methods, model objects can be created on default and switched database configurations. It also explores the implementation of chaining safety, including default non-chaining safety, Clone method cloning, Safe method setting for chaining safety, and more operational techniques.

📄️ ORM Model - Insert/SaveInsert, Replace, Save methods usage in GoFrame’s ORM chained operations, supporting automatic single or batch data insertion across various database environments. Detailed examples demonstrate how to use these methods with the Data method for data operations.

📄️ ORM Model - Update/DeletePerforming ORM chaining operations for data update and delete in the GoFrame framework. Emphasizes the importance of using the Update and Delete methods with Where conditions. Additionally, explores the feature of using Counter parameters to increase or decrease field values, and using the Increment and Decrement methods for field operations. It also explains techniques for embedding native SQL statements and implementing soft delete to ensure flexibility and security in data processing.

🗃️ ORM Model - Query11 items

🗃️ ORM Model - Association2 items

📄️ ORM Model - Object InputThis document introduces how to use the object input feature of chaining operations in the GoFrame framework, supporting various types of data parameters, providing gdb with high flexibility. It explains in detail the mapping relationships and tag priorities when using struct objects for parameter input to achieve effective database ORM conversion.

📄️ ORM Model - Fields FilteringHow to perform field filtering when operating databases with the GoFrame framework. It describes in detail the purposes and examples of the Fields and FieldsEx methods, and explores how the OmitEmpty and OmitNil features help filter out empty data during database writing. Additionally, it discusses the impact of null values on query conditions.

📄️ ORM Model - Fields RetrievalTechniques for retrieving database table fields using ORM chaining operations in the GoFrame framework, including using FieldsStr and FieldsExStr methods to retrieve fields of a specified table and uses of field exclusion, supporting custom field prefixes to enhance development efficiency and code readability.

📄️ ORM Model - TransactionUsing transaction handling in the GoFrame framework for ORM chaining methods. Through the Transaction and TX interfaces, transactional operations on the database can be achieved to ensure data consistency and reliability. Provides a detailed explanation of using the TX interface to create Model objects and the commit and rollback mechanisms in transaction handling.

📄️ ORM Model - Master/SlaveImplement master-slave configuration and read-write separation at the application layer using gdb in the GoFrame framework. With simple configuration, gdb can automatically switch between master and slave, significantly improving database performance and availability. This article also provides examples of using Master and Slave methods for custom node operations, helping developers better address issues related to master-slave synchronization delay and ensure data timeliness and accuracy.

📄️ ORM Model - Query CachePerforming query cache operations using the ORM in the GoFrame framework. It supports caching to optimize query results, suitable for scenarios with more reads and fewer writes. The article provides a detailed introduction to cache management and adaptation, especially how to implement distributed caching using Redis. It also provides sample code showing table structures and their caching effects, demonstrating query cache implementation and cache clearing functions.

🗃️ ORM Model - Time Fields4 items

📄️ ORM Model - SchemaWhen using the GoFrame framework for ORM chaining operations, the database can be switched. We can achieve various database switching schemes through different configuration groups, changing the database configuration of singleton objects at runtime, using the Schema method for chaining operations, and including the database name in table names. These methods provide developers with flexible database operation options.

📄️ ORM Model - HookUsing the Hook feature in the GoFrame framework to bind CRUD hooks to Model objects, thereby enhancing and optimizing database operations. The article provides a detailed introduction to relevant definitions, Hook registration methods, and usage examples, demonstrating query operations through hook functions.

📄️ ORM Model - HandlerUsing ORM chaining operations in the GoFrame framework to implement the Handler feature, examples demonstrate how to reuse common query logic and pagination operations, simplifying code and improving development efficiency. The Handler feature allows developers to define common logic and apply it to database models, achieving a cleaner and more maintainable code structure.

📄️ ORM Model - LockHow to implement pessimistic and optimistic locks through chaining operations in the GoFrame framework. Pessimistic locks are used to lock data during each access to prevent conflicts, commonly in high concurrency scenarios; while optimistic locks use a versioning mechanism to check data updates, suitable for scenarios with more reads and fewer writes. This document provides a detailed analysis of applicable scenarios, implementation methods, and the advantages and disadvantages of locking mechanisms to help developers optimize database performance.