Implement proper "reset" that reads snapshots from database
This commit is contained in:
13
utils/db.go
13
utils/db.go
@@ -14,6 +14,7 @@ type DB interface {
|
||||
DB() *gorm.DB
|
||||
Raw(sql string, args ...any) *gorm.DB
|
||||
SaveFile(filePath string, fileData []byte) error
|
||||
GetFile(filePath string) ([]byte, error)
|
||||
}
|
||||
|
||||
type FileSnapshot struct {
|
||||
@@ -80,3 +81,15 @@ func (db *DBWrapper) SaveFile(filePath string, fileData []byte) error {
|
||||
FileData: fileData,
|
||||
}).Error
|
||||
}
|
||||
|
||||
func (db *DBWrapper) GetFile(filePath string) ([]byte, error) {
|
||||
log := cylogger.Default.WithPrefix(fmt.Sprintf("GetFile: %q", filePath))
|
||||
log.Debug("Getting file from database")
|
||||
var fileSnapshot FileSnapshot
|
||||
err := db.db.Model(&FileSnapshot{}).Where("file_path = ?", filePath).First(&fileSnapshot).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debug("File found in database")
|
||||
return fileSnapshot.FileData, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user