GORM基础| 青训营笔记

88 阅读1分钟

这是我参与「第三届青训营 -后端场」笔记创作活动的的第2篇笔记。

  1. 课前预习 GORM语法

1.1 foreign key Screen Shot.png

1.2 Screen Shot.png Screen Shot.png Screen Shot.png Auto migration will only create tables, missing columns and indexes and won't remove stuff.
The first line of the func create three tables having the field the corresponding struct have.

Screen Shot.png db.first(...) pass in the pointer the variable that you want to unmarshall into, to determine the table you want to query, and it will only take the first one find Also, name=?, general becomes name= 'general' Similar commands in query tag on the website

1.3 db,err = gorm.Open(...)
...
defer db.close()
connect to database

db.LogMode(true)
enable logger Screen Shot.png db.Model(&a).Related(&b)
select * from b where user_id = a.user_id
find every b belongs to a
related corresponding to belong to

1.4 error handling Screen Shot.png

  1. 课堂内容 2.1 基本用法

Screen Shot.png note: 因为close可能出错 Screen Shot.png
拿error的方式 Screen Shot.png Create Record Screen Shot.png

Screen Shot.png 2.2 关联介绍 Screen Shot.png

Screen Shot.png Preload/Join Screen Shot.png 级联删除 Screen Shot.png 2.3 插件

Screen Shot.png

Screen Shot.png 2.4 ConnPool Screen Shot.png

2.5 interpolateParam=false 提高效率

2.6 dialector Screen Shot.png

2.7 数列数据化 Screen Shot.png

2.8 批量操作

Screen Shot.png

Screen Shot.png 加速操作 Screen Shot.png

2.9 代码复用

Screen Shot.png

Screen Shot.png

Screen Shot.png 3.0 sharding Screen Shot.png 4.0 Logger/Trace Screen Shot.png 5.0 安全问题

Screen Shot.png