Gorm: 终于找到了组织,这数据库不用defer db.Close()?

Created on 7 Dec 2020  ·  6Comments  ·  Source: go-gorm/gorm

从v1到v2,看示例和链接数据库里都没有defer db.Close(),新手一枚,感谢大神指点

The document you expected this should be explained

Expected answer

question

Most helpful comment

个人猜测是gorm维护了一个连接池,初始化db之后所有的连接都由库来管理。所以不需要使用者手动关闭。但这个要看源码,我只是一个猜测。

是的

All 6 comments

个人猜测是gorm维护了一个连接池,初始化db之后所有的连接都由库来管理。所以不需要使用者手动关闭。但这个要看源码,我只是一个猜测。

个人猜测是gorm维护了一个连接池,初始化db之后所有的连接都由库来管理。所以不需要使用者手动关闭。但这个要看源码,我只是一个猜测。

是的

感谢大神回复,感觉golang这些大神都能回复,真心佩服

拥抱社区,拥抱开源:)

所以 db,err:=gorm.Open() db 保存到单例就好了吗

所以 db,err:=gorm.Open() db 保存到单例就好了吗

对,gorm维护了个连接池。注册单例之后就可以一直用。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fieryorc picture fieryorc  ·  3Comments

koalacxr picture koalacxr  ·  3Comments

izouxv picture izouxv  ·  3Comments

alanyuen picture alanyuen  ·  3Comments

kumarsiva07 picture kumarsiva07  ·  3Comments