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 | 3 月前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
字节跳动云原生微服务架构原理与开源实践 CloudWeGo 技术白皮书 2024栈构建一个简易的微服务系统,真实的业务系统远比其复杂,但可以在此项目基础上进行借鉴或者扩展。 3.1.1 项目介绍 下图是Easy Note技术栈,主要分为三层,分别使用 Hertz、Kitex和GORM去编写。 Hertz负责处理用户请求,处理负责客用户直接访问的HTTP请求,包括这里也使用了Hertz的4个中间件,requestid中间件、jwt中间件、pproof中间件以及gzip中间件。 的代码生成扩展,thrift-gen-validator 去对 RPC 请求做校验。最后对数据库操作,使用了 GORM 框架,同时使用 MySQL 数据库作 RDBMS。同时也集成了 OpenTelemetry 以及 Jaeger 对链路进行追踪。 用 Logrus 日志对 Hertz、Kitex 与 GORM 默认的日 志进行替换,达成统一。 下图则是Easy Note这个biz-demo的服务调用关系图。Easy 帮助生成对应的代码以及 thrift-gen-validator,它可以帮助对 RPC 请求的结构体进行简单的校验。 建立数据库表 第二步,需要去建立一个数据库表,可以通过gorm.Model,快速地去设计数据库表的结构。包括使用gorm.Model以后,GORM也会支像软删除这样的一些功能,非常方便。 同时,也可以使用在 docker-compose.yaml 中配置 volumes 属性将 SQL 脚本挂载到0 码力 | 68 页 | 24.07 MB | 4 月前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.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.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.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
共 30 条
- 1
- 2
- 3













