mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Migrated from gorp to sqlx in store/sqlstore/plugin_store.go (#18729)
* Migrated from gorp to sqlx in store/sqlstore/plugin_store.go * fixed lint * updated QueryRowx and keys type * used QueryRowX * Fix query Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in>
This commit is contained in:
@@ -69,7 +69,7 @@ func (ps SqlPluginStore) SaveOrUpdate(kv *model.PluginKeyValue) (*model.PluginKe
|
||||
return nil, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err := ps.GetMaster().Exec(queryString, args...); err != nil {
|
||||
if _, err := ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to upsert PluginKeyValue")
|
||||
}
|
||||
|
||||
@@ -100,12 +100,20 @@ func (ps SqlPluginStore) CompareAndSet(kv *model.PluginKeyValue, oldValue []byte
|
||||
return false, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err := ps.GetMaster().Exec(queryString, args...); err != nil {
|
||||
if _, err = ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
return false, errors.Wrap(err, "failed to delete PluginKeyValue")
|
||||
}
|
||||
|
||||
// Insert if oldValue is nil
|
||||
if err := ps.GetMaster().Insert(kv); err != nil {
|
||||
queryString, args, err = ps.getQueryBuilder().
|
||||
Insert("PluginKeyValueStore").
|
||||
Columns("PluginId", "PKey", "PValue", "ExpireAt").
|
||||
Values(kv.PluginId, kv.Key, kv.Value, kv.ExpireAt).ToSql()
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err := ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
// If the error is from unique constraints violation, it's the result of a
|
||||
// race condition, return false and no error. Otherwise we have a real error and
|
||||
// need to return it.
|
||||
@@ -135,7 +143,7 @@ func (ps SqlPluginStore) CompareAndSet(kv *model.PluginKeyValue, oldValue []byte
|
||||
return false, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
updateResult, err := ps.GetMaster().Exec(queryString, args...)
|
||||
updateResult, err := ps.GetMasterX().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to update PluginKeyValue")
|
||||
}
|
||||
@@ -166,7 +174,8 @@ func (ps SqlPluginStore) CompareAndSet(kv *model.PluginKeyValue, oldValue []byte
|
||||
return false, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
count, err := ps.GetReplica().SelectInt(queryString, args...)
|
||||
var count int64
|
||||
err = ps.GetReplicaX().Get(&count, queryString, args...)
|
||||
if err != nil {
|
||||
return false, errors.Wrapf(err, "failed to count PluginKeyValue with pluginId=%s and key=%s", kv.PluginId, kv.Key)
|
||||
}
|
||||
@@ -214,7 +223,7 @@ func (ps SqlPluginStore) CompareAndDelete(kv *model.PluginKeyValue, oldValue []b
|
||||
return false, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
deleteResult, err := ps.GetMaster().Exec(queryString, args...)
|
||||
deleteResult, err := ps.GetMasterX().Exec(queryString, args...)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "failed to delete PluginKeyValue")
|
||||
}
|
||||
@@ -262,7 +271,7 @@ func (ps SqlPluginStore) Get(pluginId, key string) (*model.PluginKeyValue, error
|
||||
return nil, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
row := ps.GetReplica().Db.QueryRow(queryString, args...)
|
||||
row := ps.GetReplicaX().QueryRowx(queryString, args...)
|
||||
var kv model.PluginKeyValue
|
||||
if err := row.Scan(&kv.PluginId, &kv.Key, &kv.Value, &kv.ExpireAt); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -285,7 +294,7 @@ func (ps SqlPluginStore) Delete(pluginId, key string) error {
|
||||
return errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err := ps.GetMaster().Exec(queryString, args...); err != nil {
|
||||
if _, err := ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to delete PluginKeyValue with pluginId=%s and key=%s", pluginId, key)
|
||||
}
|
||||
return nil
|
||||
@@ -301,7 +310,7 @@ func (ps SqlPluginStore) DeleteAllForPlugin(pluginId string) error {
|
||||
return errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err := ps.GetMaster().Exec(queryString, args...); err != nil {
|
||||
if _, err := ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrapf(err, "failed to get all PluginKeyValues with pluginId=%s ", pluginId)
|
||||
}
|
||||
return nil
|
||||
@@ -319,7 +328,7 @@ func (ps SqlPluginStore) DeleteAllExpired() error {
|
||||
return errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
if _, err := ps.GetMaster().Exec(queryString, args...); err != nil {
|
||||
if _, err := ps.GetMasterX().Exec(queryString, args...); err != nil {
|
||||
return errors.Wrap(err, "failed to delete all expired PluginKeyValues")
|
||||
}
|
||||
return nil
|
||||
@@ -334,8 +343,6 @@ func (ps SqlPluginStore) List(pluginId string, offset int, limit int) ([]string,
|
||||
offset = 0
|
||||
}
|
||||
|
||||
var keys []string
|
||||
|
||||
query := ps.getQueryBuilder().
|
||||
Select("Pkey").
|
||||
From("PluginKeyValueStore").
|
||||
@@ -353,7 +360,8 @@ func (ps SqlPluginStore) List(pluginId string, offset int, limit int) ([]string,
|
||||
return nil, errors.Wrap(err, "plugin_tosql")
|
||||
}
|
||||
|
||||
_, err = ps.GetReplica().Select(&keys, queryString, args...)
|
||||
keys := []string{}
|
||||
err = ps.GetReplicaX().Select(&keys, queryString, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get PluginKeyValues with pluginId=%s", pluginId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user