definition
GORM (Golang Object Relational Mapping): Map an instance of an object or structure in Go to a piece of data in the database through ORM statements (instead of SQL).
ORM has the following correspondence:
- datatable<==>struct
- data row <==> struct instance
- field <==> struct field
Install
First of all, if you are in China, running the installation command directly may have the same timeout problem as installing gin. If this problem occurs, you can first enter it on the command line:
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
Then run the install command again
go get -u gorm.io/gorm
Connect to the database
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
func main() {
db, _ := gorm.Open("mysql", "user:password@(localhost)/dbname?charset=utf8mb4&parseTime=True&loc=Local")
defer db.Close()
}
refer to:
bilibili
https://gorm.io/zh_CN/docs/
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。