This commit is contained in:
2023-12-21 21:11:41 +03:00
parent ed1716232a
commit 0d727a4011

View File

@ -9,6 +9,7 @@ import (
"gitea.home.4it.me/dilap54/platiparser/gorm"
"gitea.home.4it.me/dilap54/platiparser/plati"
"github.com/urfave/cli/v2"
"gorm.io/gorm/clause"
)
func init() {
@ -65,7 +66,6 @@ func saveCategories(db *gorm.DB, categories plati.Categories) error {
if err := saveCategories(db, c.Children); err != nil {
return err
}
continue
}
gormCategories = append(gormCategories, &gorm.Category{
@ -81,7 +81,7 @@ func saveCategories(db *gorm.DB, categories plati.Categories) error {
log.Printf("saving %d categories to db", len(gormCategories))
if err := db.Create(gormCategories).Error; err != nil {
if err := db.Clauses(clause.OnConflict{DoNothing: true}).Create(gormCategories).Error; err != nil {
return fmt.Errorf("db Create: %w", err)
}