initial pase store definitions

This commit is contained in:
juancwu 2026-05-04 18:39:25 +00:00
commit b947535795
10 changed files with 723 additions and 0 deletions

48
store/nullables.go Normal file
View file

@ -0,0 +1,48 @@
package store
import (
"database/sql"
"encoding/json"
)
type NullTime sql.NullTime
func (nt NullTime) MarshalJSON() ([]byte, error) {
if nt.Valid {
return json.Marshal(nt.Time)
}
return []byte("null"), nil
}
func (nt *NullTime) UnmarshalJSON(data []byte) error {
if string(data) == "null" || string(data) == `""` {
nt.Valid = false
return nil
}
if err := json.Unmarshal(data, &nt.Time); err != nil {
return err
}
nt.Valid = true
return nil
}
type NullString sql.NullString
func (ns NullString) MarshalJSON() ([]byte, error) {
if ns.Valid {
return json.Marshal(ns.String)
}
return []byte("null"), nil
}
func (ns *NullString) UnmarshalJSON(data []byte) error {
if string(data) == "null" || string(data) == `""` {
ns.Valid = false
return nil
}
if err := json.Unmarshal(data, &ns.String); err != nil {
return err
}
ns.Valid = true
return nil
}