Skip to content

Commit

Permalink
修复单条查询时连接泄露问题 (#188)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: chenhaokun <chenhaokun@itiger.com>
Co-authored-by: Ming Deng <mingflycash@gmail.com>
  • Loading branch information
3 people authored Apr 7, 2023
1 parent 19f56ff commit 3fae3b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions .CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [eorm: 分库分表: Merger分页实现](https://github.com/ecodeclub/eorm/pull/175)
- [eorm: BasicTypeValue重命名](https://github.com/ecodeclub/eorm/pull/177)
- [eorm: 分库分表: hash、shadow_hash算法不符合预期](https://github.com/ecodeclub/eorm/pull/174)
- [eorm: 修复单条查询时连接泄露问题](https://github.com/ecodeclub/eorm/pull/188)

## v0.0.1:
- [Init Project](https://github.com/ecodeclub/eorm/pull/1)
Expand Down
8 changes: 8 additions & 0 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func getHandler[T any](ctx context.Context, sess Session, c core, qc *QueryConte
if err != nil {
return &QueryResult{Err: err}
}
defer func() {
_ = rows.Close()
}()
if !rows.Next() {
return &QueryResult{Err: errs.ErrNoRows}
}
Expand All @@ -53,6 +56,7 @@ func getHandler[T any](ctx context.Context, sess Session, c core, qc *QueryConte
if err = val.SetColumns(rows); err != nil {
return &QueryResult{Err: err}
}

return &QueryResult{Result: tp}
}

Expand All @@ -72,6 +76,9 @@ func getMultiHandler[T any](ctx context.Context, sess Session, c core, qc *Query
if err != nil {
return &QueryResult{Err: err}
}
defer func() {
_ = rows.Close()
}()
res := make([]*T, 0, 16)
meta := qc.meta
if meta == nil {
Expand All @@ -91,6 +98,7 @@ func getMultiHandler[T any](ctx context.Context, sess Session, c core, qc *Query
}
res = append(res, tp)
}

return &QueryResult{Result: res}
}

Expand Down

0 comments on commit 3fae3b6

Please sign in to comment.