摘要: 1. 简单创建记录 user := User{Name: "李四", Age: 88, Birthday: time.Now()} ret := db.Create(&user) // 通过数据的指针来创建 fmt.Println(user.ID) // 返回插入数据的主键 fmt.Println( 阅读全文
posted @ 2021-11-16 19:19 专职 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 1. mysql的初始化配置 dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?%s", user, passwd, host, port, db, other) //db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{ 阅读全文
posted @ 2021-11-16 15:16 专职 阅读(2349) 评论(0) 推荐(0) 编辑
摘要: 模型定义 模型是标准的结构体,由go的基本数据类型、实现了Scanner和Valuer接口的自定义类型及其指针或别名组成 例如: type User struct { ID uint Name string Email *string Age uint8 Birthday *time.Time Me 阅读全文
posted @ 2021-11-16 14:50 专职 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 特性 全功能 ORM 关联 (Has One,Has Many,Belongs To,Many To Many,多态,单表继承) Create,Save,Update,Delete,Find 中钩子方法 支持 Preload、Joins 的预加载 事务,嵌套事务,Save Point,Rollbac 阅读全文
posted @ 2021-11-16 10:52 专职 阅读(143) 评论(0) 推荐(0) 编辑