Chore: remove xorm from preference (#53803)

* Chore: remove xorm from preference

* separte feature toggle

* fix comments

* fix comments

* remove the dublicated namedexec
This commit is contained in:
ying-jeanne
2022-08-17 22:07:20 -04:00
committed by GitHub
parent 4ac87a3b3b
commit 82b63688d2
10 changed files with 247 additions and 103 deletions
+36 -13
View File
@@ -2,27 +2,29 @@ package pref
import (
"bytes"
"database/sql/driver"
"encoding/json"
"errors"
"fmt"
"time"
)
var ErrPrefNotFound = errors.New("preference not found")
type Preference struct {
ID int64 `xorm:"pk autoincr 'id'"`
OrgID int64 `xorm:"org_id"`
UserID int64 `xorm:"user_id"`
TeamID int64 `xorm:"team_id"`
Teams []int64 `xorm:"extends"`
Version int
HomeDashboardID int64 `xorm:"home_dashboard_id"`
Timezone string
WeekStart string
Theme string
Created time.Time
Updated time.Time
JSONData *PreferenceJSONData `xorm:"json_data"`
ID int64 `xorm:"pk autoincr 'id'" db:"id"`
OrgID int64 `xorm:"org_id" db:"org_id"`
UserID int64 `xorm:"user_id" db:"user_id"`
TeamID int64 `xorm:"team_id" db:"team_id"`
Teams []int64 `xorm:"extends"`
Version int `db:"version"`
HomeDashboardID int64 `xorm:"home_dashboard_id" db:"home_dashboard_id"`
Timezone string `db:"timezone"`
WeekStart string `db:"week_start"`
Theme string `db:"theme"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
JSONData *PreferenceJSONData `xorm:"json_data" db:"json_data"`
}
type GetPreferenceWithDefaultsQuery struct {
@@ -94,6 +96,27 @@ func (j *PreferenceJSONData) FromDB(data []byte) error {
return dec.Decode(j)
}
func (j *PreferenceJSONData) Scan(val interface{}) error {
switch v := val.(type) {
case []byte:
if len(v) == 0 {
return nil
}
return json.Unmarshal(v, &j)
case string:
if len(v) == 0 {
return nil
}
return json.Unmarshal([]byte(v), &j)
default:
return fmt.Errorf("unsupported type: %T", v)
}
}
func (j *PreferenceJSONData) Value() (driver.Value, error) {
return j.ToDB()
}
func (j *PreferenceJSONData) ToDB() ([]byte, error) {
if j == nil {
return nil, nil