add callback

This commit is contained in:
ideaa
2024-07-08 08:58:39 +08:00
parent 52d80f632f
commit 2c31cabc5b
4 changed files with 40 additions and 0 deletions

View File

@@ -14,6 +14,9 @@ import (
type SQLiteStore struct {
configKey string
callback callback
hasCallback bool
}
func (m *SQLiteStore) Config() *config.Sqlite {
@@ -26,6 +29,11 @@ func (m *SQLiteStore) Config() *config.Sqlite {
return r
}
func (m *SQLiteStore) Callback(fn callback) {
m.callback = fn
m.hasCallback = true
}
func (m *SQLiteStore) Use() *gorm.DB {
r := m.Config()
if r == nil {
@@ -45,6 +53,10 @@ func (m *SQLiteStore) Use() *gorm.DB {
return nil
}
if m.hasCallback {
m.callback(db)
}
sqlDB, err := db.DB()
if err != nil {
logger.SugarLog.Error("Ping SQLite error",