mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
Move mapping functions to db_ledis, where it is used
This commit is contained in:
parent
52fc580a2b
commit
93ab4132fe
2 changed files with 6 additions and 6 deletions
|
@ -26,7 +26,7 @@ func (r *ledisRepository) init(table string, entity interface{}) {
|
||||||
r.table = table
|
r.table = table
|
||||||
r.entityType = reflect.TypeOf(entity).Elem()
|
r.entityType = reflect.TypeOf(entity).Elem()
|
||||||
|
|
||||||
h, _ := utils.ToMap(entity)
|
h, _ := toMap(entity)
|
||||||
r.fieldNames = make([]string, len(h))
|
r.fieldNames = make([]string, len(h))
|
||||||
i := 0
|
i := 0
|
||||||
for k := range h {
|
for k := range h {
|
||||||
|
@ -160,7 +160,7 @@ func (r *ledisRepository) saveOrUpdate(id string, entity interface{}) error {
|
||||||
recordPrefix := fmt.Sprintf("%s:%s:", r.table, id)
|
recordPrefix := fmt.Sprintf("%s:%s:", r.table, id)
|
||||||
allKey := r.table + "s:all"
|
allKey := r.table + "s:all"
|
||||||
|
|
||||||
h, err := utils.ToMap(entity)
|
h, err := toMap(entity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ func (r *ledisRepository) toEntity(response [][]byte, entity interface{}) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return utils.ToStruct(record, entity)
|
return toStruct(record, entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ledisRepository) loadRange(idxName string, min interface{}, max interface{}, entities interface{}, qo ...domain.QueryOptions) error {
|
func (r *ledisRepository) loadRange(idxName string, min interface{}, max interface{}, entities interface{}, qo ...domain.QueryOptions) error {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package utils
|
package db_ledis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ToMap(rec interface{}) (map[string]interface{}, error) {
|
func toMap(rec interface{}) (map[string]interface{}, error) {
|
||||||
// Convert to JSON...
|
// Convert to JSON...
|
||||||
b, err := json.Marshal(rec)
|
b, err := json.Marshal(rec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -17,7 +17,7 @@ func ToMap(rec interface{}) (map[string]interface{}, error) {
|
||||||
return m, err
|
return m, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToStruct(m map[string]interface{}, rec interface{}) error {
|
func toStruct(m map[string]interface{}, rec interface{}) error {
|
||||||
// Convert to JSON...
|
// Convert to JSON...
|
||||||
b, err := json.Marshal(m)
|
b, err := json.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
Loading…
Add table
Add a link
Reference in a new issue