From 44721921a5588b4c44aafadce54a72c97059d6b0 Mon Sep 17 00:00:00 2001 From: Ebrahim Nejati Date: Tue, 30 Apr 2024 00:12:05 +0330 Subject: [PATCH] Update event on conflict --- handlers/handle_commands.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/handlers/handle_commands.go b/handlers/handle_commands.go index 8fb6ba4..fc59b4f 100644 --- a/handlers/handle_commands.go +++ b/handlers/handle_commands.go @@ -1,12 +1,14 @@ package handlers import ( - "gorm.io/gorm" "strconv" "strings" "github.com/DearRude/siahe/database" in "github.com/DearRude/siahe/internals" + + "gorm.io/gorm" + "gorm.io/gorm/clause" ) func handleCommands(u in.UpdateMessage) error { @@ -533,7 +535,10 @@ func addEventCommand(u in.UpdateMessage) error { IsActive: true, // An event is a active by default } - res := db.Create(&event) + res := db.Clauses(clause.OnConflict{ + Columns: []clause.Column{{Name: "name"}}, + DoUpdates: clause.AssignmentColumns([]string{"description", "is_paid", "max_ticket_batch", "place_id"}), + }).Create(&event) if err := res.Error; err != nil { if err := reactToMessage(u, "👎"); err != nil { return err