db
This commit is contained in:
@ -9,6 +9,7 @@ import (
|
|||||||
"gitea.home.4it.me/dilap54/platiparser/gorm"
|
"gitea.home.4it.me/dilap54/platiparser/gorm"
|
||||||
"gitea.home.4it.me/dilap54/platiparser/plati"
|
"gitea.home.4it.me/dilap54/platiparser/plati"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
"gorm.io/gorm/clause"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -65,7 +66,6 @@ func saveCategories(db *gorm.DB, categories plati.Categories) error {
|
|||||||
if err := saveCategories(db, c.Children); err != nil {
|
if err := saveCategories(db, c.Children); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gormCategories = append(gormCategories, &gorm.Category{
|
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))
|
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)
|
return fmt.Errorf("db Create: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user