Skip to content

Commit

Permalink
p2p: fix node db opedration
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Apr 8, 2024
1 parent 4b3ac88 commit 8b3fff2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/p2p-Node/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ func SubscribeTopics(ps *pubsub.PubSub, h host.Host, ctx context.Context) {

func CreateOrUpdate(db *gorm.DB, node *models.Node) error {
var model models.Node
if err := db.Model(&models.Node{}).First(node.Id).Error; err != nil {

if err := db.First(&model, node.Id).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return db.Model(&models.Node{}).Create(&node).Error
return db.Create(node).Error
}
return err
}
return db.Model(&models.Node{}).Updates(model).Error

return db.Model(&model).Updates(node).Error
}

0 comments on commit 8b3fff2

Please sign in to comment.