Merge pull request #572 from t924417424/main

fix: The sqlite database file is not updated because the database con…
pull/581/head
北野 - Michael 4 months ago committed by GitHub
commit de7cf353b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -18,6 +18,7 @@ import (
"github.com/rocboss/paopao-ce/cmd"
"github.com/rocboss/paopao-ce/internal"
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/dao"
"github.com/rocboss/paopao-ce/internal/service"
"github.com/rocboss/paopao-ce/pkg/debug"
"github.com/rocboss/paopao-ce/pkg/utils"
@ -47,6 +48,7 @@ func init() {
}
func deferFn() {
dao.CloseDsx()
if cfg.If("Sentry") {
// Flush buffered events before the program terminates.
sentry.Flush(2 * time.Second)

@ -34,6 +34,14 @@ func MustGormDB() *gorm.DB {
return _gormdb
}
func CloseGormDB() {
db, err := _gormdb.DB()
if err != nil {
log.Fatalf("close gorm db failed: %s", err)
}
_ = db.Close()
}
func newGormDB() (db *gorm.DB, err error) {
newLogger := logger.New(
logrus.StandardLogger(), // io writer日志输出的目标前缀和日志包含的内容

@ -88,6 +88,19 @@ func initDsX() {
logrus.Infof("use %s as core.ServantA with version %s", dsaVer.Name(), dsaVer.Version())
}
func CloseDsx() {
if cfg.If("Gorm") {
jinzhu.CloseDbObject()
} else if cfg.If("Sqlx") {
sakila.CloseDbObject()
} else if cfg.If("Sqlc") && cfg.Any("Postgres", "PostgreSQL") {
slonik.CloseDbObject()
} else {
// default use gorm as orm for sql database
jinzhu.CloseDbObject()
}
}
func initOSS() {
var v core.VersionInfo
if cfg.If("AliOSS") {

@ -87,6 +87,10 @@ func NewDataService() (core.DataService, core.VersionInfo) {
return cache.NewCacheDataService(ds), ds
}
func CloseDbObject() {
conf.CloseGormDB()
}
func NewWebDataServantA() (core.WebDataServantA, core.VersionInfo) {
lazyInitial()
db := conf.MustGormDB()

@ -26,3 +26,7 @@ func NewAuthorizationManageService() core.AuthorizationManageService {
logrus.Fatal("not support now")
return nil
}
func CloseDbObject() {
logrus.Fatal("not support now")
}

@ -26,3 +26,7 @@ func NewAuthorizationManageService() core.AuthorizationManageService {
logrus.Fatal("not support now")
return nil
}
func CloseDbObject() {
logrus.Fatal("not support now")
}

@ -5,7 +5,7 @@
<n-list class="main-content-wrap" bordered>
<n-list-item>
<n-spin :show="loading">
<div class="detail-wrap" v-if="post.id > 1">
<div class="detail-wrap" v-if="post.id > 0">
<post-detail :post="post" @reload="reloadPost" />
</div>
<div class="empty-wrap" v-else>

Loading…
Cancel
Save