2.2.7 GORM 剖析与最佳实践中国 上海 / 2020-11.21-22 GORM剖析与最佳实践 张金柱 @ 字节跳动 ’ alt=‘OCR图片’/> Jinzhu/张金柱 Github: @jinzhu 字节跳动:@zhangjinzhu GORM 官网:https://gorm.io https://gorm.cn (国内CDN) 2020.gorm.cn GORM 五分钟快速入门 SQL 是怎么生成的(Locking,Optimizer Hints,Batch Upsert) 插件是怎么工作的(读写分离,Open Tracing,压测平台) 最佳实践 & FAQ GORM五分钟快速入门-初始化 import "gorm.io/gorm" import "gorm.io/driver/mysql" // 模型定义 type Product struct { ID uint // 连接数据库 // 连接数据库 dsn := "gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True&loc=Local" db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{ Logger: logger.Default0 码力 | 29 页 | 4.68 MB | 1 月前3
TiDB v6.1 DocumentationStep 2. Get the code git clone https://github.com/pingcap-inc/tidb-example-golang.git Compared with GORM, the go-sql-driver/mysql implementation might be not a best practice, because you need to write error close *sql.Rows manually and cannot reuse code easily, which makes your code slightly redundant. GORM is a popular open-source ORM library for Golang. The following instructions take v1.23.5 as an example Change to the gorm directory: cd gorm The structure of this directory is as follows: Makefile go.mod go.sum gorm.go gorm.go is the main body of the gorm. Compared with go-sql-driver/mysql, GORM avoids differences0 码力 | 4487 页 | 84.44 MB | 2 年前3
TiDB v6.1 中文手册ang.git 当前开源比较流行的 Golang ORM 为 GORM,此处将以 v1.23.5 版本进行说明。 ```javascript package util import ( "gorm.io/gorm" ) // TiDBGormBegin start a TiDB and Gorm transaction as a block. If no error committed. Otherwise, the transaction will be rolled back. func TiDBGormBegin(db *gorm.DB, pessimistic bool, fc func(tx *gorm.DB) error) (err error) { ```  ```javascript session := db.Session(&gorm.Session{}) if session.Error != nil { return session.Error } if pessimistic { session = session.Exec("set0 码力 | 3572 页 | 84.36 MB | 2 年前3
TiDB v7.1 Documentationneed to write complex SQL statements, it is recommended to use ORM framework for development, such as GORM. It can help you: - Reduce boilerplate code for managing connections and transactions. - Manipulate support ticket. ## 4.3.2.2 Connect to TiDB with GORM TiDB is a MySQL-compatible database, and GORM is a popular open-source ORM framework for Golang. GORM adapts to TiDB features such as AUTO_RANDOM and this tutorial, you can learn how to use TiDB and GORM to accomplish the following tasks: - Set up your environment. - Connect to your TiDB cluster using GORM. - Build and run your application. Optionally0 码力 | 5716 页 | 104.74 MB | 2 年前3
TiDB v6.5 Documentationneed to write complex SQL statements, it is recommended to use ORM framework for development, such as GORM. It can help you: - Reduce boilerplate code for managing connections and transactions. ## 4.3.2 support ticket. ## 4.3.2.2 Connect to TiDB with GORM TiDB is a MySQL-compatible database, and GORM is a popular open-source ORM framework for Golang. GORM adapts to TiDB features such as AUTO_RANDOM and this tutorial, you can learn how to use TiDB and GORM to accomplish the following tasks: - Set up your environment. - Connect to your TiDB cluster using GORM. - Build and run your application. Optionally0 码力 | 5282 页 | 99.69 MB | 2 年前3
TiDB v8.0 Documentationneed to write complex SQL statements, it is recommended to use ORM framework for development, such as GORM. It can help you: - Reduce boilerplate code for managing connections and transactions. ## 4.3.2 support ticket. ## 4.3.2.2 Connect to TiDB with GORM TiDB is a MySQL-compatible database, and GORM is a popular open-source ORM framework for Golang. GORM adapts to TiDB features such as AUTO_RANDOM and this tutorial, you can learn how to use TiDB and GORM to accomplish the following tasks: - Set up your environment. - Connect to your TiDB cluster using GORM. - Build and run your application. Optionally0 码力 | 6327 页 | 107.55 MB | 2 年前3
TiDB v7.6 Documentationneed to write complex SQL statements, it is recommended to use ORM framework for development, such as GORM. It can help you: - Reduce boilerplate code for managing connections and transactions. - Manipulate support ticket. ## 4.3.2.2 Connect to TiDB with GORM TiDB is a MySQL-compatible database, and GORM is a popular open-source ORM framework for Golang. GORM adapts to TiDB features such as AUTO_RANDOM and this tutorial, you can learn how to use TiDB and GORM to accomplish the following tasks: - Set up your environment. - Connect to your TiDB cluster using GORM. - Build and run your application. Optionally0 码力 | 6123 页 | 107.24 MB | 2 年前3
TiDB v7.5 Documentationneed to write complex SQL statements, it is recommended to use ORM framework for development, such as GORM. It can help you: - Reduce boilerplate code for managing connections and transactions. ## 4.3.2 support ticket. ## 4.3.2.2 Connect to TiDB with GORM TiDB is a MySQL-compatible database, and GORM is a popular open-source ORM framework for Golang. GORM adapts to TiDB features such as AUTO_RANDOM and this tutorial, you can learn how to use TiDB and GORM to accomplish the following tasks: - Set up your environment. - Connect to your TiDB cluster using GORM. - Build and run your application. Optionally0 码力 | 6020 页 | 106.82 MB | 2 年前3
TiDB v8.2 Documentationneed to write complex SQL statements, it is recommended to use ORM framework for development, such as GORM. It can help you: - Reduce boilerplate code for managing connections and transactions. - Manipulate support ticket. ## 4.3.2.2 Connect to TiDB with GORM TiDB is a MySQL-compatible database, and GORM is a popular open-source ORM framework for Golang. GORM adapts to TiDB features such as AUTO_RANDOM and this tutorial, you can learn how to use TiDB and GORM to accomplish the following tasks: - Set up your environment. - Connect to your TiDB cluster using GORM. - Build and run your application. Optionally0 码力 | 6549 页 | 108.77 MB | 1 年前3
TiDB v8.1 Documentationneed to write complex SQL statements, it is recommended to use ORM framework for development, such as GORM. It can help you: - Reduce boilerplate code for managing connections and transactions. ## 4.3.2 support ticket. ## 4.3.2.2 Connect to TiDB with GORM TiDB is a MySQL-compatible database, and GORM is a popular open-source ORM framework for Golang. GORM adapts to TiDB features such as AUTO_RANDOM and this tutorial, you can learn how to use TiDB and GORM to accomplish the following tasks: - Set up your environment. - Connect to your TiDB cluster using GORM. - Build and run your application. Optionally0 码力 | 6321 页 | 107.46 MB | 2 年前3
共 29 条
- 1
- 2
- 3













