From 7b9aeca7ff6aab4db772cf68431f55fbbca9320c Mon Sep 17 00:00:00 2001 From: Saul Pinales <46951371+spinales@users.noreply.github.com> Date: Tue, 5 Oct 2021 11:52:50 -0400 Subject: [PATCH] Migrate from gorp to sqlx in store/sqlstore/command_webhook_store.go (#18517) * Migrate from gorp to sqlx in store/sqlstore/command_webhook_store.go * fixing small things change `CreatedAt` to `CreateAt` and change GetReplicaX().Select to GetReplicaX().Get Co-authored-by: Saul Pinales --- store/sqlstore/command_webhook_store.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/store/sqlstore/command_webhook_store.go b/store/sqlstore/command_webhook_store.go index 48d7316744..cba63cbefb 100644 --- a/store/sqlstore/command_webhook_store.go +++ b/store/sqlstore/command_webhook_store.go @@ -47,7 +47,10 @@ func (s SqlCommandWebhookStore) Save(webhook *model.CommandWebhook) (*model.Comm return nil, err } - if err := s.GetMaster().Insert(webhook); err != nil { + if _, err := s.GetMasterX().NamedExec(`INSERT INTO CommandWebhooks + (Id,CreateAt,CommandId,UserId,ChannelId,RootId,UseCount) + Values + (:Id, :CreateAt, :CommandId, :UserId, :ChannelId, :RootId, :UseCount)`, webhook); err != nil { return nil, errors.Wrapf(err, "save: id=%s", webhook.Id) } @@ -70,7 +73,7 @@ func (s SqlCommandWebhookStore) Get(id string) (*model.CommandWebhook, error) { return nil, errors.Wrap(err, "get_tosql") } - if err := s.GetReplica().SelectOne(&webhook, queryString, args...); err != nil { + if err := s.GetReplicaX().Get(&webhook, queryString, args...); err != nil { if err == sql.ErrNoRows { return nil, store.NewErrNotFound("CommandWebhook", id) } @@ -92,7 +95,7 @@ func (s SqlCommandWebhookStore) TryUse(id string, limit int) error { return errors.Wrap(err, "tryuse_tosql") } - if sqlResult, err := s.GetMaster().Exec(queryString, args...); err != nil { + if sqlResult, err := s.GetMasterX().Exec(queryString, args...); err != nil { return errors.Wrapf(err, "tryuse: id=%s limit=%d", id, limit) } else if rows, _ := sqlResult.RowsAffected(); rows == 0 { return store.NewErrInvalidInput("CommandWebhook", "id", id) @@ -115,7 +118,7 @@ func (s SqlCommandWebhookStore) Cleanup() { return } - if _, err := s.GetMaster().Exec(queryString, args...); err != nil { + if _, err := s.GetMasterX().Exec(queryString, args...); err != nil { mlog.Error("Unable to cleanup command webhook store.") } }