mirror of
https://github.com/wonli/aqi.git
synced 2025-10-05 08:36:58 +08:00
add callback
This commit is contained in:
@@ -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",
|
||||
|
Reference in New Issue
Block a user