Output user pronoun database valuer

This commit is contained in:
Melon 2024-06-12 14:38:49 +01:00
parent 9bea6805d5
commit 69fa6a4812
Signed by: melon
GPG Key ID: 6C9D970C50D26A25

View File

@ -2,6 +2,7 @@ package types
import ( import (
"database/sql" "database/sql"
"database/sql/driver"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/mrmelon54/pronouns" "github.com/mrmelon54/pronouns"
@ -27,7 +28,13 @@ func (p *UserPronoun) Scan(src any) error {
p.Pronoun = pro p.Pronoun = pro
return nil return nil
} }
func (p *UserPronoun) Value() (driver.Value, error) {
return p.Pronoun.String(), nil
}
func (p UserPronoun) MarshalJSON() ([]byte, error) { return json.Marshal(p.Pronoun.String()) } func (p UserPronoun) MarshalJSON() ([]byte, error) { return json.Marshal(p.Pronoun.String()) }
func (p *UserPronoun) UnmarshalJSON(bytes []byte) error { func (p *UserPronoun) UnmarshalJSON(bytes []byte) error {
var a string var a string
err := json.Unmarshal(bytes, &a) err := json.Unmarshal(bytes, &a)