mirror of
https://github.com/go-gorm/gorm.git
synced 2025-02-02 20:28:40 +08:00
Add FindInBatches
parent
d179c6174f
commit
5b59e42333
@ -8,7 +8,7 @@ GORM 2.0 是基于用户过去几年中的反馈进行思考后的重写,在
|
|||||||
|
|
||||||
* 性能优化
|
* 性能优化
|
||||||
* 代码模块化
|
* 代码模块化
|
||||||
* Context、批量插入、Prepared Statment、DryRun 模式、Join Preload, Find 到 Map 支持
|
* Context、批量插入、Prepared Statment、DryRun 模式、Join Preload, Find 到 Map, FindInBatches 支持
|
||||||
* 关联关系,替换 Join Table,Association 模式对批量数据支持及优化
|
* 关联关系,替换 Join Table,Association 模式对批量数据支持及优化
|
||||||
* SQL Builder 优化, Upsert, Locking
|
* SQL Builder 优化, Upsert, Locking
|
||||||
* 插入时间、更新时间可同时支持多字段,并加入unix (nano) second 支持
|
* 插入时间、更新时间可同时支持多字段,并加入unix (nano) second 支持
|
||||||
@ -142,6 +142,27 @@ var results []map[string]interface{}
|
|||||||
DB.Model(&User{}).Find(&results)
|
DB.Model(&User{}).Find(&results)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### FindInBatches
|
||||||
|
|
||||||
|
批量查询数据处理
|
||||||
|
|
||||||
|
```go
|
||||||
|
DB.Where("processed = ?", false).FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
|
||||||
|
// 批量数据处理
|
||||||
|
for _, result := range results {
|
||||||
|
result.Processed = true
|
||||||
|
}
|
||||||
|
DB.Save(&results)
|
||||||
|
|
||||||
|
tx.RowsAffected // 返回本批数据的数量
|
||||||
|
|
||||||
|
batch // 第几批次
|
||||||
|
|
||||||
|
// 返回错误中止后续批量处理
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
### 关联关系支持优化
|
### 关联关系支持优化
|
||||||
|
|
||||||
* 对于 Belongs To, 单表 Belongs To, Has One, Has One Polymorphic, Has Many, Has Many Polymorphic, 单表 Has Many, Many2Many, 单表 Many2Many 关系支持重新进行了实现,避免部分极端情况下判断关联错误
|
* 对于 Belongs To, 单表 Belongs To, Has One, Has One Polymorphic, Has Many, Has Many Polymorphic, 单表 Has Many, Many2Many, 单表 Many2Many 关系支持重新进行了实现,避免部分极端情况下判断关联错误
|
||||||
|
Loading…
Reference in New Issue
Block a user