-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b38d951
commit f703847
Showing
6 changed files
with
96 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package config | ||
|
||
type Sync struct { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package db | ||
|
||
import ( | ||
"github.com/goexl/gox" | ||
"github.com/goexl/gox/field" | ||
"github.com/goexl/log" | ||
"github.com/pangum/db/internal/config" | ||
) | ||
|
||
type Synchronizer struct { | ||
gox.CannotCopy | ||
|
||
engine *Engine | ||
config *config.Sync | ||
logger log.Logger | ||
} | ||
|
||
func NewSynchronizer(engine *Engine, config *config.Sync, logger log.Logger) *Synchronizer { | ||
return &Synchronizer{ | ||
engine: engine, | ||
config: config, | ||
logger: logger, | ||
} | ||
} | ||
|
||
func (s *Synchronizer) Sync(models ...any) (err error) { | ||
fields := gox.Fields[any]{ | ||
field.New("models", models), | ||
field.New("config", s.config), | ||
} | ||
s.logger.Info("同步数据库表开始", fields...) | ||
if err = s.engine.Sync(models...); nil == err { | ||
s.logger.Info("同步数据库表成功", fields...) | ||
} else { | ||
s.logger.Error("同步数据库表失败", fields...) | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package db | ||
|
||
import ( | ||
"github.com/pangum/db/internal/db" | ||
) | ||
|
||
// Synchronizer 同步器 | ||
type Synchronizer = db.Synchronizer |