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>
Этот коммит содержится в:
@@ -69,7 +69,7 @@ func (ps SqlPluginStore) SaveOrUpdate(kv *model.PluginKeyValue) (*model.PluginKe
|
|||||||
return nil, errors.Wrap(err, "plugin_tosql")
|
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")
|
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")
|
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")
|
return false, errors.Wrap(err, "failed to delete PluginKeyValue")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert if oldValue is nil
|
// 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
|
// 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
|
// race condition, return false and no error. Otherwise we have a real error and
|
||||||
// need to return it.
|
// need to return it.
|
||||||
@@ -135,7 +143,7 @@ func (ps SqlPluginStore) CompareAndSet(kv *model.PluginKeyValue, oldValue []byte
|
|||||||
return false, errors.Wrap(err, "plugin_tosql")
|
return false, errors.Wrap(err, "plugin_tosql")
|
||||||
}
|
}
|
||||||
|
|
||||||
updateResult, err := ps.GetMaster().Exec(queryString, args...)
|
updateResult, err := ps.GetMasterX().Exec(queryString, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.Wrap(err, "failed to update PluginKeyValue")
|
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")
|
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 {
|
if err != nil {
|
||||||
return false, errors.Wrapf(err, "failed to count PluginKeyValue with pluginId=%s and key=%s", kv.PluginId, kv.Key)
|
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")
|
return false, errors.Wrap(err, "plugin_tosql")
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteResult, err := ps.GetMaster().Exec(queryString, args...)
|
deleteResult, err := ps.GetMasterX().Exec(queryString, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.Wrap(err, "failed to delete PluginKeyValue")
|
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")
|
return nil, errors.Wrap(err, "plugin_tosql")
|
||||||
}
|
}
|
||||||
|
|
||||||
row := ps.GetReplica().Db.QueryRow(queryString, args...)
|
row := ps.GetReplicaX().QueryRowx(queryString, args...)
|
||||||
var kv model.PluginKeyValue
|
var kv model.PluginKeyValue
|
||||||
if err := row.Scan(&kv.PluginId, &kv.Key, &kv.Value, &kv.ExpireAt); err != nil {
|
if err := row.Scan(&kv.PluginId, &kv.Key, &kv.Value, &kv.ExpireAt); err != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
@@ -285,7 +294,7 @@ func (ps SqlPluginStore) Delete(pluginId, key string) error {
|
|||||||
return errors.Wrap(err, "plugin_tosql")
|
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 errors.Wrapf(err, "failed to delete PluginKeyValue with pluginId=%s and key=%s", pluginId, key)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -301,7 +310,7 @@ func (ps SqlPluginStore) DeleteAllForPlugin(pluginId string) error {
|
|||||||
return errors.Wrap(err, "plugin_tosql")
|
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 errors.Wrapf(err, "failed to get all PluginKeyValues with pluginId=%s ", pluginId)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -319,7 +328,7 @@ func (ps SqlPluginStore) DeleteAllExpired() error {
|
|||||||
return errors.Wrap(err, "plugin_tosql")
|
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 errors.Wrap(err, "failed to delete all expired PluginKeyValues")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -334,8 +343,6 @@ func (ps SqlPluginStore) List(pluginId string, offset int, limit int) ([]string,
|
|||||||
offset = 0
|
offset = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
var keys []string
|
|
||||||
|
|
||||||
query := ps.getQueryBuilder().
|
query := ps.getQueryBuilder().
|
||||||
Select("Pkey").
|
Select("Pkey").
|
||||||
From("PluginKeyValueStore").
|
From("PluginKeyValueStore").
|
||||||
@@ -353,7 +360,8 @@ func (ps SqlPluginStore) List(pluginId string, offset int, limit int) ([]string,
|
|||||||
return nil, errors.Wrap(err, "plugin_tosql")
|
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 {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to get PluginKeyValues with pluginId=%s", pluginId)
|
return nil, errors.Wrapf(err, "failed to get PluginKeyValues with pluginId=%s", pluginId)
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user