Migrating OAuthStore to sqlx (#18302)
* Migrating OAuthStore to sqlx https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4?c=71efa7c4-53be-4732-87cc-d53726d2cd53 ```release-note NONE ``` * Fixing some broken tests ```release-note NONE ``` Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
bbd5ba9ff2
Коммит
17fe158f5e
@@ -6,6 +6,7 @@ package model
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"database/sql/driver"
|
||||
"encoding/base32"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -24,6 +25,7 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/shared/i18n"
|
||||
"github.com/pborman/uuid"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -72,6 +74,30 @@ func (sa StringArray) Equals(input StringArray) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Value converts StringArray to database value
|
||||
func (sa StringArray) Value() (driver.Value, error) {
|
||||
return json.Marshal(sa)
|
||||
}
|
||||
|
||||
// Scan converts database column value to StringArray
|
||||
func (sa *StringArray) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
buf, ok := value.([]byte)
|
||||
if ok {
|
||||
return json.Unmarshal(buf, sa)
|
||||
}
|
||||
|
||||
str, ok := value.(string)
|
||||
if ok {
|
||||
return json.Unmarshal([]byte(str), sa)
|
||||
}
|
||||
|
||||
return errors.New("received value is neither a byte slice nor string")
|
||||
}
|
||||
|
||||
var translateFunc i18n.TranslateFunc
|
||||
var translateFuncOnce sync.Once
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user